views:

83

answers:

3

I have an MVC action that pulls an image from a database and sends it in the response via the File(byte[], string) method. When I navigate to the action in my browser, it downloads the file rather than display it in the browser.

I'm setting the file and setting the content type to "image/jpeg". Is there another header that needs to be set in order to get it to do what I want it to do?

+1  A: 

Response.ContentType

Response.ContentType = "image/jpeg";
Jonathan
I'm sorry, I meant I set the content type, not the mime-type.
MojoFilter
A: 

I would use Fiddler to compare your response headers with a normal static JPG's response headers. That will tell you for sure.

David
+1  A: 

Ok, mystery solved.

Controller.File() has an overload that takes no filename; just data and content-type. Using that overload causes the content-disposition to be set correctly. In retrospect, I guess that makes a lot of sense.

MojoFilter