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?
Step 1 - Go to SQL Server Management System and execute the following script. Step 2 - Go to Visual studio and add a new project. Select “Asp.Net MVC 4 Web Application” and give the name for this ,In my case it is “MVCDemoProject. ” -> Select a Project template as Empty and View engine is “Razor”, Then Click OK.
To return a model from the controller action method to the view, we need to pass the model/object in the View() method. Here, the View gets the model as UserNamePasswordModel object with its property set. To retrieve properties of this object in the view, we can use @Model ; like @Model.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With