0

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

3
  • Looks like you're mixing single quotes with double. Try "<img src=\""+data.ImagePath+"\" />" instead Commented Jun 22, 2016 at 12:43
  • 1
    have you tried fixing your append to: $("#cbox").append("<img src='" + data.ImagePath + "' />") ? Commented Jun 22, 2016 at 12:43
  • Thanks,I will try and will update outcome Commented Jun 22, 2016 at 12:50

1 Answer 1

1

Change

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

to

 $("#cbox").append("<img src='" +data.ImagePath+ "' />")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.