簡體   English   中英

使用提供PDF文件結果的ASP.NET MVC操作在Chrome中填充對象標記的數據屬性

[英]Populating the data attribute of an object tag in Chrome with an ASP.NET MVC action that serves a PDF file result

我有一個返回PDF的FileResult操作。 我想將此PDF嵌入到對象標記中。 當我將操作插入到對象標記的data屬性中時,如下所示,Chrome中不會檢索或顯示PDF。 (PDF在帶有Adobe插件的Firefox中顯示 - 我不關心IE。)

<object data="@Url.Action("GetPDF", "PDFCreation", new {id= Model.DocumentId})" type="application/pdf"></object>

這一切都是有效的 - 對象標簽與文件系統上的PDF直接鏈接(例如,data =“〜/ Content / test.pdf”)和上面的Action,如果硬粘貼到位置欄,下載PDF。

有什么想法嗎? 謝謝!

我設法讓IE顯示使用FileContentResult和以下對象標記拋出的Pdf

<object>
    <embed src="@Url.Action("GetPDF", "PDFCreation", new {id= Model.DocumentId})" type="application/pdf"></embed>
</object>

也許值得嘗試一下

通過這個答案修復它: 將文件返回到ASP.NET MVC中的View / Download

必須附加內容處置標頭,並將內容處置的“內聯”值設置為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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM