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
retireve multiple images from database and show in view
Jul 15 2017 6:17 AM
i am trying to show an image in view. i am using mvc 5 now, below is my view code and server side code. so please help me how i show a single image or multiple images from database,
view code,
@model NewAuthentication.ViewModel.PhotoViewModel
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>myprof</title>
</head>
<body>
<div>
<table>
<tbody>
<tr>
<td>
<img src="@Model.photo" />
</td> </tr>
</tbody>
</table>
</div></body>
</html>
and server side code,
i create a viewmodel which is shown below,
public class PhotoViewModel
{
public int id { get; set; }
public string photo { get; set; }
public string firstname { get; set; }
public string Gender { get; set; }
}
and action method code is below,
public ActionResult myprof()
{
SqlConnection con = new SqlConnection("Data Source=JAGDISH;Database=Hmarasmaj;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("Select photo from ParentImages where pid="+1+"",con);
DataTable dt = new DataTable();
da.Fill(dt);
int c = dt.Rows.Count;
PhotoViewModel p = new PhotoViewModel();
byte[] img =(byte[]) dt.Rows[0]["photo"];
p.photo = "data:image/png;base64," + Convert.ToBase64String(img);
return View(p);
}
Reply
Answers (
1
)
Compress and uncompressed video size
image not show in view after retrieve from database