Hi,
I was wondering if anybody knows how to Display an image from a database in a MVC view? At the moment I have an upload view which allows a user to upload an image and all these images are displayed in a webgrid in a Edit view with a "Delete" button next to image record. I want the Delete button to take the user to a new view where the image they have clicked on is displayed so they know they are deleting the correct one,
I have set up separate views and controllers for the new "DeleteItemImage" function which will display the image, but all are empty at the moment,
Any help would be appreciated,
Nick
Here is my code for the Images webgrid in the Edit view:
<table style="width:100%">
@{
var imagesGrid = new WebGrid(Model.ItemImages);
}
@imagesGrid.GetHtml(tableStyle: "webgrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
(columns: imagesGrid.Columns(
imagesGrid.Column("Sequence_No_", header: "Sequence No"),
imagesGrid.Column("Image_Title", header: "Image Title"),
imagesGrid.Column("Main_Image", header: "Primary Image"),
imagesGrid.Column("Uploaded", header: "Uploaded to LinnWorks"),
imagesGrid.Column("",
format: @<text>
@Html.ActionLink("Delete", "DeleteItemImage");
</text>),
imagesGrid.Column("",
format:@<text>
@Html.ActionLink("Select", null, new { selectImage = Model.SelectImage })
</text>),
imagesGrid.Column("",
format:@<text>
@Html.ActionLink("Make Primary", null, new { makePrimary = Model.MakeMainImage })
</text>
))))
</table>
Here is my code for the Edit action result:
public ActionResult Edit(string itemNo)
{
LinnWorksItemViewModel model = new LinnWorksItemViewModel(_data.Connection.ConnectionString, itemNo);
return View(model);
foreach (string upload in Request.Files)
{
if (!Request.Files[upload].HasFile()) continue;
string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
string fileName = Path.GetFileName(Request.Files[upload].FileName);
Request.Files[upload].SaveAs(Path.Combine(path, fileName));
}
return View(model);
}