我有一个ASP.NET网站,它以PDF形式生成报告。我想将该PDF加载到我的视图中的IFRAME中。但是当我尝试时,它总是会提示我下载PDF。我尝试过使用File()方法,返回一个新的FileContectResult(),甚至只是使用Response.BinaryWrite(),但似乎没有什么窍门。任何人有任何好的建议?将生成的PDF数据加载到ASP.NET MVC的IFRAME中
这里是从视图的剃刀代码:
<script>
$(document).ready(function() {
var url = $('#reportUrl').val();
$("#iframe1").attr("src", url);
});
</script>
<input type="hidden" id="reportUrl" value="@Url.Action("ContactListPDF2","Reports")" />
<div class="block-head">
<div class="item-content">
<iframe id="iframe1" style="border: 1px solid black; height: 500px; width: 100%">
</iframe>
</div>
</div>
这里是我的控制器适当的方法:
public ActionResult ContactListPDF2()
{
byte[] reportData = ReportsModel.GetContactListPDF();
return new FileContentResult(reportData, "application/pdf");
}
我知道我失去了一些东西简单明了,但对于意味着我的生活可以确定它是什么。
选中此项 - http://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html – malkam 2015-04-03 06:55:06