I have a table containing user information with image field and storing image in binary data.
I want to show this images on my view page in a table with user information.
my code is.. Controller
public ActionResult About()
{
var data = db.dbtable.ToList();
return View(data);
}
Get Image method // reg is object of dbtable
public FileContentResult GetImage(int id)
{
reg = db.dbtable.FirstOrDefault(i => i.RegNo == id);
if (reg != null)
{
return File(reg.Photo, "image/jpeg");
}
else
{
return null;
}
}
on view page..
@model IEnumerable<MvcMySchool.dbtable>
<table width="50">
<tr>
<th>
Registration No.
</th>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>
City
</th>
<th>
Photo
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.RegNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@*HttpContext.Current.Response.Write("<img width="75" height="75" src=@(Url.Action("GetImage", "Home", new { id = item.RegNo })) />")*@
<img width="75" height="75" src=@(Url.Action("GetImage", "Home", new { id = item.RegNo })) />
</td>
</tr>
}
</table>
It only shows the image in the first row and nothing after that.
Thanks..
May make more sense just to keep the path the image.
If you filesteam,
more logical way to keep, ony way
for both