在MVC中保存文件对话框

时间:2011-07-25 13:17:10

标签: asp.net-mvc savefiledialog

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

提前致谢。

1 个答案:

答案 0 :(得分:6)

在返回要下载的文件时使用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");
}