i retrieve image from database but after vconverting base64 not show in view below is the server side code
- public ActionResult myprof()
{
SqlConnection con = new SqlConnection("Data Source=JAGDISH;Database=Hmarasmaj;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("Select top(1) photo from ParentImages where pid="+1+"",con);
DataTable dt = new DataTable();
da.Fill(dt);
int c = dt.Rows.Count;
DataModel dm = new DataModel();
byte[] img =(byte[]) dt.Rows[0]["photo"];
dm.Photo = img;
return View(dm);
}
and below is the view code,
- @model NewAuthentication.Models.DataModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>myprof</title>
</head>
<body>
<div>
@{
var base64 = Convert.ToBase64String(Model.Photo);
var imgsrc = string.Format("data:image/jpeg;base64,{0}", base64);
}
<img src="@imgsrc" width="100" />
</div>
</body>
</html>
public ActionResult myprof()
{
SqlConnection con = new SqlConnection("Data Source=JAGDISH;Database=Hmarasmaj;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("Select top(1) photo from ParentImages where pid="+1+"",con);
DataTable dt = new DataTable();
da.Fill(dt);
int c = dt.Rows.Count;
DataModel dm = new DataModel();
byte[] img =(byte[]) dt.Rows[0]["photo"];
dm.Photo = img;
return View(dm);
}