Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Image binding MVC actionresult razor view
Chaitanya
Feb 7 2016 3:51 AM
509
Reply
Hi all I am binding the img tag as follows
<img alt=
""
src=
'@Url.Action("UserImage", "Home")'
class
=
"avatar img-circle img-thumbnail"
/>
This is my code to get the image from the database
[HttpGet]
public
ActionResult UserImage()
{
string
user = Session[
"UserName"
]
as
string
;
byte
[] photo =
null
;
var v = db.table.Where(p => p.USER_NAME == user).Select(img => img.PHOTO).FirstOrDefault();
if
(v !=
null
)
{
photo = v;
return
File(photo,
"image/jpeg"
);
}
else
return
null
;
}
This is displaying image when I have in the database but when it is null it is displaying as follows, instead of that i need to bind src tag with empty
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
how can we use abstraction and polymorphism in project
Auto suggest dropdownlist/listbox/etc.-URGENT