流式传输一个byte 以在jquery模式中加载为PDF(MVC3)

当使用MVC3单击某个链接时,我正在尝试流式传输一个byte []以加载到jquery模式中。 在我的控制器中我有

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文件。

任何帮助?

iframe可能是你的答案。

问题是ajax无法在浏览器中加载pdf,显示pdf你必须指定内容配置并且浏览器在他里面显示pdf

指定内容处置添加标题

 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

  

这是一个解决方案[查看/打印/保存PDF],它通过MVC-ajax调用从byte []生成PDF模式对话框。 它是由其他地方的其他一些半相关职位建立的。 有两个选项:PrintDialog1使用object标签,而PrintDialog2使用iframe标签。

控制器>>

 [Post] public ActionResult DoSomethingThatResultsInCreatingAPdf(CreatePaymentViewModel model) { byte[] pdf = DoSomethingThatResultsInCreatingAPdfByteArray(); string strPdf = System.Convert.ToBase64String(pdf); var returnOjb = new { success = true, pdf = strPdf, errors = "" ...otherParams}; return Json(returnOjb, JsonRequestBehavior.AllowGet); } 

剃刀页>>