Verma
Verma

Reputation: 39

ASP.NET MVC display image from json result

Image is not displaying from json result value. Below is my Controller Action and Jquery

$.post('/User/Comment/',{commentId=Id},function(data){

  $("#cbox").append("<img src="'+data.ImagePath+'" />")

});

Controller:

public ActionResult Comment(string commentId){
     var data=(from p in db.commentdb
     join q in db.profileImage
     on p.Email equals q.Email
     where p.commentId==commentId
     select new
    {
     Name=p.Fullname,
     Comment=p.Comment
     ImagePath=q.ImagePath
     });
    return Json(data,jsonrequestbehavior.allowget)
   }

Please help to fix this. Just I need to display image on razor view based on json return image path

Upvotes: 0

Views: 1108

Answers (1)

Paul Swetz
Paul Swetz

Reputation: 2254

Change

$("#cbox").append("<img src="'+data.ImagePath+'" />")

to

 $("#cbox").append("<img src='" +data.ImagePath+ "' />")

Upvotes: 1

Related Questions