流式传输一个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

<iframe src="@url("GetTermsAndCondtion","NameOfYourController")" width="400" height="500" scrolling="auto" frameborder="1">
</iframe>

相关文章

1.第一步 设置响应头 header(&#39;Access-Control-Allow...
$.inArray()方法介绍 $.inArray()函数用于在数组中搜索指定的...
jquery.serializejson.min.js的妙用 关于这个jquery.seriali...
JS 将form表单数据快速转化为object对象(json对象) jaymou...
jQuery插件之jquery.spinner数字智能增减插件 参考地址:http...