Reputation: 15541
I am pretty new to MVC 2 and would be grateful for any help.
In my database I have a field for the thumbnail which is stored as a System.Drawing.BitMap.
I have a partial view that needs to generate the image in the html.
I have seen links to FileResult but this is the controller. With model binding how do I embed the image in the generated html page from a partial view?
Not sure if I need some "image" tag in my html or what format the data from the partial view must be in for it to show the thumbnail?
JD
Upvotes: 2
Views: 3503
Reputation: 1038820
You need to have a controller action which returns a FileStreamResult and then use an <img>
tag pointing to this controller action.
public ActionResult Image(int id)
{
byte[] imageData = GetImageFromDb(id);
return File(imageData, "image/jpeg");
}
And then inside your view:
<img src="<%: Url.Action("image", new { id = Model.ImageId }) %>" alt="some image" />
Upvotes: 8