流一个byte []以在PDF格式的jQuery模态中加载(MVC3) [英] stream a byte[] to load inside a jquery modal as PDF (MVC3)
本文介绍了流一个byte []以在PDF格式的jQuery模态中加载(MVC3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用MVC3单击某个链接时,我正在尝试流式传输byte []以加载到jquery模态中. 在我的控制器中,
I am trying to stream a byte[] to load inside a jquery modal when a certain link is clicked using MVC3. In my controller I have
public ActionResult GetTermsAndCondtion()
{
byte[] termsPdf = GetTermsAndConditions(DateTime.Now);
return new FileContentResult(termsPdf, "application/pdf");
}
我认为我有
@Html.ActionLink("Terms and Conditon","GetTermsAndCondtion","Customer", new{id="terms"})
这将在选项卡中打开pdf文件.但是我想在模态文件中将byte []作为pdf文件打开.
This opens the pdf file in a tab. But I want to open the byte[] as pdf file inside a modal.
有帮助吗?
推荐答案
iframe可能是您的答案.
Iframe could be your answer.
问题是ajax无法将pdf加载到浏览器中,要显示pdf,必须指定内容配置,浏览器在其中显示pdf
The problem it's that ajax can't load the pdf it inside the browser, to show a pdf you must specified the content disposition and the browser show the pdf inside him
指定内容配置添加标头
HttpContext.Response.AddHeader("content-disposition", "inline; filename=MyFile.pdf")
Return File(fileStream, "application/pdf")
控制器
public ActionResult GetTermsAndCondtion()
{
byte[] termsPdf = GetTermsAndConditions(DateTime.Now);
HttpContext.Response.AddHeader("content-disposition", "inline; filename=MyFile.pdf");
return File(termsPdf, "application/pdf");
}
最后将这个iframe添加到您的模式中
And finally add this iframe inside your modal
<iframe src="@url("GetTermsAndCondtion","NameOfYourController")" width="400" height="500" scrolling="auto" frameborder="1">
</iframe>
这篇关于流一个byte []以在PDF格式的jQuery模态中加载(MVC3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文