As you may know we have got a new ActionResult called FileResult in RC1 version of ASP.NET MVC.
Using that, your action methods can return image to browser dynamically. Something like this:
public ActionResult DisplayPhoto(int id)
{
Photo photo = GetPhotoFromDatabase(id);
return File(photo.Content, photo.ContentType);
}
In the HTML code, we can use something like this:
<img src="http://mysite.com/controller/DisplayPhoto/657">
Since the image is returned dynamically, we need a way to cache the returned stream so that we don't need to read the image again from database. I guess we can do it with something like this, I'm not sure:
Response.StatusCode = 304;
This tells the browser that you already have the image in your cache. I just don't know what to return in my action method after setting StatusCode to 304. Should I return null or something?