我正在使用 MVC 在 View 中显示 PDF 内容,但无法正确呈现。
控制器动作:
[HttpPost]
public ActionResult GetDocumentContent()
{
byte[] result;
result = System.IO.File.ReadAllBytes(@"C:\test.pdf");
Response.AppendHeader("Content-Disposition", new System.Net.Mime.ContentDisposition
{
FileName = "document.pdf",
Inline = true,
}.ToString());
return File(result, "application/pdf");
}
查询:
var url = "/DocumentContent/GetDocumentContent";
var self = this;
$.post(url, null,function (data) {
debugger;
var obj = $('<object type="application/pdf" width="100%" height="100%" border="2"></object>');
obj.attr('data', data);
$('#divContainer').append(obj);
});
这段代码有什么错误?如何在 View 中显示 PDF 流?