How return 304 status with FileResult in ASP.NET MVC RC1

Posted by Maysam on Stack Overflow See other posts from Stack Overflow or by Maysam
Published on 2009-03-02T12:14:39Z Indexed on 2010/05/30 8:22 UTC
Read the original article Hit count: 348

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about cache