Save file dialog in MVC

被刻印的时光 ゝ 提交于 2019-12-19 07:47:10

问题


How to create save file dialog in MVC application? I couldn't find any example.

Thanks in advance.


回答1:


By using the Content-Disposition header to attachment when returning the file to download:

public ActionResult Download()
{
    return File(@"c:\work\report.pdf", "application/pdf", "reoprt.pdf");
}

Or if the file to download is dynamically generated:

public ActionResult Download()
{
    byte[] pdf = ... get the contents of the report
    return File(pdf, "application/pdf", "reoprt.pdf");
}


来源:https://stackoverflow.com/questions/6816727/save-file-dialog-in-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!