Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
image not show in view after retrieve from database
Jagdish Suryawanshi
Jul 15 2017 7:58 AM
192
Reply
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);
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
retireve multiple images from database and show in view
How to double click on column header to edit mode using MVC