流一个字节 [] 以在 jquery 模态中加载为 PDF (MVC3) [英] stream a byte[] to load inside a jquery modal as PDF (MVC3)

查看:17
本文介绍了流一个字节 [] 以在 jquery 模态中加载为 PDF (MVC3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 MVC3 单击某个链接时,我正在尝试流式传输一个字节 [] 以在 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");
        }

在我的一个观点中,我有

In one of my view I have

@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>

这篇关于流一个字节 [] 以在 jquery 模态中加载为 PDF (MVC3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆