I am new to ASP.NET MVC so please don't judge me... I am having a problem where the image from my SQL Server (byte data type) is not showing to my view. It says "Cannot convert the byte[] to string". What should I do?
This is my controller method ViewProduct:
public ActionResult ViewProduct()
{
return View();
}
public ActionResult ViewProd()
{
inventoryDBEntities1 dbe = new inventoryDBEntities1();
return View(dbe.tbl_product.ToList());
}
This is my model class named tbl_product:
public partial class tbl_product
{
public int productID { get; set; }
public byte[] prod_image { get; set; }
}
And this is my view:
@model IEnumerable<PointofSale.Models.tbl_product>
<table>
<tr>
<td>
Image
</td>
</tr>
<tr>
@foreach (var item in @Model)
{
<td>
// The error is around here ( V )!!
<img src="@Url.Content(item.prod_image)" height="100" width="100"/>
</td>
}
</tr>
</table>
@Url.Contentexpects a string that represents a file path in your application's virtual directory, e.g.:"~/images/exampleImage.png"One might be curious as to why you'd store something like that in abyte[]property. Is it possible thatprod_imagedoesn't hold a file path but instead holds the raw bytes of a binary image?