i stored few images in database in binary format, now i want to display those images in my view,how can we convert those images from binary format to image format again?
this is my action menthod in my controller
public ActionResult DislpayAllImage()
{
DataSet dsa = new DataSet();
dsa = objImage.getAllImages();
DataTable dt = new DataTable();
dt = dsa.Tables[0];
if (dt != null)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Byte[] image = (Byte[])dt.Rows[i]["UsImage"];
return File(image, "image/jpg");
}
}
return View();
}
this is my code in model
public DataSet getUserImage(int Id)
{
DataSet ds = new DataSet();
try
{
DbCommand db = dbcon.GetStoredProcCommand("GetImage");
dbcon.AddInParameter(db, "@Id", DbType.Int16, Id);
db.CommandType = CommandType.StoredProcedure;
return ds = dbconstr.ExecuteDataSet(dbCmd);
}
catch(Exception ex)
{
return ds = null;
}
}
view
@foreach( var image in ViewData.Images )
{
<img src="@Url.Action("DislpayImage", "Home",new { id = image.ImageID })" />
}
how can i display my image in razor view,also is the above code fine?