如何在 MVC 应用程序中创建保存文件对话框?我找不到任何例子。
提前致谢。
通过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");
}