Rotativa PDF导出 - 无法同时显示内联和文件名

out*_*ind 3 asp.net-mvc rotativa

我发现Rotativa是一种轻松导出为PDF的方法(除了CSS3之外几乎完全没有支持,可能在将来的版本中使用)...但我想知道如何处理该FileName选项.

当我

return new Rotativa.ViewAsPdf("myViewName", "~/Views/Shared/_PDFLayout.cshtml", myModel)
{
    FileName = "myCorrectlyNamed.pdf",
    PageSize = ... // plus some more options
};
Run Code Online (Sandbox Code Playgroud)

然后我会myCorrectlyNamed.pdf下载.当我省略该FileName选项时,PDF将显示在浏览器中,但是当我从那里保存时,它只有默认文件名document.pdf.

如何在浏览器中生成和显示pdf,并且文件名不是document.pdf从那里保存的?

sac*_*hin 6

您可以添加Content-Disposition标题Response.使用此标头,您将能够告诉浏览器内联显示文件,并指定用户尝试保存文件时应使用名称.

Response.AppendHeader("Content-Disposition", new System.Net.Mime.ContentDisposition { Inline = true, FileName = "myCorrectlyNamed.pdf" }.ToString());
return new Rotativa.ViewAsPdf("myViewName", "~/Views/Shared/_PDFLayout.cshtml", myModel)
{
    PageSize = ... // plus some more options
};
Run Code Online (Sandbox Code Playgroud)