Render image to the screen from MVC controller

前端 未结 3 1487
生来不讨喜
生来不讨喜 2020-12-16 07:32

I have images in the database and I want to return the image for viewing from an action. Here\'s my action.

public FileContentResult Index(ItemImageRequest          


        
3条回答
  •  情书的邮戳
    2020-12-16 07:52

    The File ActionResult adds a line to the HTTP header like this:

    Content-disposition: attachment; filename=foo
    

    This will cause the browser to attempt to download the file. That's why there is an overload to specify the filename.

    You can create your own ActionResult to do the downloading, and omit the Content-disposition.

    If you want to copy-and-paste, I have the code for one on codeplex: ImageResult.cs

提交回复
热议问题