我有一个动作,在新的浏览器选项卡中显示PDF.
public ActionResult Print()
{
var cd = new ContentDisposition
{
FileName ="something.pdf",
Inline = true
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(reportResponse.Data.Document, MediaTypeNames.Application.Pdf);
}
文件名工作正常.当我下载文件时,它的名字我想要“something.pdf”.
问题是当谷歌浏览器在新的浏览器选项卡中打开PDF时,它显示控制器操作名称(打印)作为PDF的标题.这就是我想要改变的.我附上了一张图片,用于澄清
查看代码:
Url.Action(“打印”,“控制器”,新{area =“Area”}),新{@target =“_ blank”}
最佳答案 对于文件名的操作方法传递参数,并确保参数名称为“id”.
View code: Url.Action("Print", "Controller", new { id = "filename", area = "Area" }), new { @target = "_blank" }
public ActionResult Print(id)
{
var cd = new ContentDisposition
{
FileName ="something.pdf",
Inline = true
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(reportResponse.Data.Document, MediaTypeNames.Application.Pdf);
}`