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

Therefore, I use MVC 2 to display some images from the controller action. Common wisdom ( 1 , 2 , 3 ), it seems you should use one of the FileResult types ( FileStreamResult , FileContentResult or `FileContentResult ').

All three specific FileResult 's, however, set the Content-Disposition response header using attachment; filename{YourFileNameHere}=UTF-8 attachment; filename{YourFileNameHere}=UTF-8 . The end result is that if the user views my image directly, and is not embedded in HTML, the browser displays a save dialog rather than showing the image. I would prefer the image to just display in the browser.

I think this begs my question: Using MVC 2 How can I return the result of an image where the image is NOT marked for upload?

+6
asp.net-mvc-2
source share
1 answer

In MVC, the FileResult.FileDownloadName property is used to determine whether to send content to a string or as an attachment. If you are creating a type based on FileResult, do not set its FileDownloadName property. In addition, if you use the Controller.File factory methods, call an overload that does not accept the fileDownloadName argument (or passes a null value for this argument).

+5
source share

All Articles