Chaitanya

Chaitanya

  • NA
  • 58
  • 57k

Image binding MVC actionresult razor view

Feb 7 2016 3:51 AM
Hi all I am binding the img tag as follows
  1. <img alt="" src='@Url.Action("UserImage", "Home")' class="avatar img-circle img-thumbnail" />  
This is my code to get the image from the database
  1. [HttpGet]  
  2. public ActionResult UserImage()  
  3. {  
  4. string user = Session["UserName"as string;  
  5. byte[] photo = null;  
  6. var v = db.table.Where(p => p.USER_NAME == user).Select(img => img.PHOTO).FirstOrDefault();  
  7. if (v != null)  
  8. {  
  9. photo = v;  
  10. return File(photo, "image/jpeg");  
  11. }  
  12. else  
  13. return null;  
  14. }  
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
 
 

Answers (2)