4

如何在 MVC 应用程序中创建保存文件对话框?我找不到任何例子。

提前致谢。

4

1 回答 1

7

通过Content-Disposition在返回文件下载时使用附件标题:

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

或者,如果要下载的文件是动态生成的:

public ActionResult Download()
{
    byte[] pdf = ... get the contents of the report
    return File(pdf, "application/pdf", "reoprt.pdf");
}
于 2011-07-25T13:32:01.817 回答