I am trying to display a picture that I am calling from the controller using AJAX, this is my code:
<div id="productImg" style="display:none;">
</div>
<script>
function showPic(id) {
$.ajax({
type: "GET",
url: "/Equipment/GetImage",
data: { 'productId': id },
success: function (data) {
$("#productImg").html(data)
}
});
</script>
And the method on my controller looks like this:
public virtual FileContentResult GetImage(int productId) {
Product prod = _db.Products.FirstOrDefault(p => p.ProductID == productId);
if (prod != null) {
return File(prod.ImageData, prod.ImageMimeType);
} else {
return null;
}
}
What I am getting is a lot of code and not the image. What else could I try?