错误转换MVC4以PDF与Rotativa或RazorPDF [英] Error converting MVC4 view to PDF with Rotativa or RazorPDF

查看:386
本文介绍了错误转换MVC4以PDF与Rotativa或RazorPDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换MVC4视图为PDF。
几分钟后搜索,我发现

I am trying to convert a MVC4 view to Pdf. after a few minutes searching I found

https://www.nuget.org/packages/Rotativa/

https://www.nuget.org/packages/RazorPDF

这两个给我将在下面解释同样的问题:

both give me the same problem that will be explained below:

我通过在Mvc4项目的NuGet安装Rotativa 1.6.1。

I installed Rotativa 1.6.1 via nuget in a Mvc4 project.

我的例子中的操作方法是这样的:

my example action method looks like this:

[HttpGet]
public ViewAsPdf TestPdf()
{
  return new ViewAsPdf("TestPdf");
}

我的例子视图以下列方式构建:

my example view is structured in the following manner:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport"  />
    <title>TestPdf</title>
</head>
<body>
    <div>
        This is a test!
    </div>
</body>
</html>

当我与我的浏览器访问的操作方法,我得到以下结果。

when I access the action method with my browser, I get the following result.

为什么不被显示的PDF任何想法?

any Idea on why the pdf is not being shown?

当我尝试RazorPDF同样的错误发生。

this same error happens when I try with RazorPDF.

推荐答案

我曾与asp.net的MVC 4和Rotativa同样的问题。在我的web.config中添加了System.Web.Mvc绑定重定向解决了我的问题。

I had the same problem with asp.net mvc 4 and Rotativa. Adding a binding redirect for System.Web.Mvc in my web.config solve the problem for me.

<runtime>
    <dependentAssembly>
       <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
           <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
           </dependentAssembly>
    </assemblyBinding>
</runtime>

这篇关于错误转换MVC4以PDF与Rotativa或RazorPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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