Gab*_*abe 5 .net c# asp.net asp.net-mvc google-chrome
我有一个返回PDF的FileResult操作.我想将此PDF嵌入到对象标记中.当我将操作插入到对象标记的data属性中时,如下所示,Chrome中不会检索或显示PDF.(PDF在带有Adobe插件的Firefox中显示 - 我不关心IE.)
<object data="@Url.Action("GetPDF", "PDFCreation", new {id= Model.DocumentId})" type="application/pdf"></object>
Run Code Online (Sandbox Code Playgroud)
这一切都是有效的 - 对象标签与文件系统上的PDF直接链接(例如,data ="〜/ Content/test.pdf")和上面的Action,如果硬粘贴到位置栏,下载PDF.
有什么想法吗?谢谢!
通过这个答案修复了它:Returning a file to View/Download in ASP.NET MVC
必须附加内容处置标头,并将内容处置的“内联”值设置为 true。
var doc = ...
var contentDisposition = new ContentDisposition
{
FileName = doc.FileName,
Inline = true
};
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
return File(doc.Path, MediaTypeNames.Application.Pdf);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2017 次 |
| 最近记录: |