EBarr
EBarr

Reputation: 12026

How to return image from controller without setting Content-Disposition tag?

So I'm using MVC 2 to serve up some images from a Controller Action. General wisdom (1, 2, 3) seems to be to use one of the FileResult types (FileStreamResult, FileContentResult or `FileContentResult').

All three concrete FileResult's, however, set the Content-Disposition response header with attachment; filename{YourFileNameHere}=UTF-8. The net result is that if a user views my image directly, rather than embedded in HTML, the browser present a save dialog, rather than displaying the image. I would prefer the image simply display in the browser.

I guess that makes my question: Using MVC 2 What is the appropriate way to return an image result where the image is NOT marked for download?

Upvotes: 7

Views: 1194

Answers (1)

Levi
Levi

Reputation: 32818

The MVC framework uses the FileResult.FileDownloadName property to determine whether to send the content inline or as an attachment. If you're instantiating a FileResult-derived type directly, don't set its FileDownloadName property. Alternatively, if you're using the Controller.File factory methods, call an overload which doesn't take a fileDownloadName argument (or pass in null for that argument).

Upvotes: 6

Related Questions