asp.net-mvc-3 – 在MVC 3的浏览器选项卡中打开PDF结果
|
我使用ASP.NET MVC 3.我有一个控制器操作,返回一个PDF文件,如下所示: Public Class ReportController
...
Function Generate(id As Integer) As ActionResult
...
Return File(output,"application/pdf","something.pdf")
' "output" is a memory stream
End Function
代码可以工作,但Firefox不会在标签页中显示结果,结果是使用Adobe Reader下载或打开. 我知道Firefox可以在选项卡中显示PDF,因为我可以只是google一些PDF,点击链接,PDF将在一个选项卡中打开. 如何设置操作,以便PDF在标签中打开? 解决方法我从 related links on the right得到答案:Response.AppendHeader("Content-Disposition","inline")
Return File(output,"application/pdf")
PDF在标签页中打开,但是文件名提示丢失,即使我这样做: Response.AppendHeader("Content-Disposition","inline; filename=something.pdf")
Return File(output,"something.pdf")
所以终于我没有打扰给出文件名提示. 编辑 ASP.NET MVC 3的文件有3个参数: Return File(output,"something.pdf") 将添加Content-Disposition:attachment; filename =“something.pdf”到响应头,即使响应头中已经有Content-Disposition. 所以如果你手动添加Content-Disposition到标题,然后使用3个参数的File,最终得到两个Content-Disposition标题.如果响应头像这样,Firefox 8会说响应被破坏了. 所以现在最好的方法是手动添加Content-Disposition为’inline’,然后使用带有2个参数的File: Response.AppendHeader("Content-Disposition","application/pdf") (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 如何在ASP.NET MVC应用程序中实现搜索功能
- 使用ASP.NET/SQL Server丢失会话状态
- asp.net – IE10中的LinkButtons不执行回发
- 重命名控制器asp.net mvc
- asp.net-mvc – LabelFor和TextBoxFor不生成相同的id
- asp.net 文章内容分页显示的代码
- .net – 如何获得程序集最后修改日期?
- asp.net-mvc – HttpResponse.RemoveOutputCacheItem不工作
- asp.net-mvc – ASP.NET MVC 5身份应用程序用户作为外键
- asp.net-mvc – 从ASP.NET在Office Web Apps中打开excel /
