TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jagdish Suryawanshi
NA
11
4.2k
image not show in view after retrieve from database
Jul 15 2017 7:58 AM
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);
}
Reply
Answers (
1
)
retireve multiple images from database and show in view
How to double click on column header to edit mode using MVC