[英]Error converting MVC4 view to PDF with Rotativa or RazorPDF
I am trying to convert a MVC4 view to Pdf. 我试图将MVC4视图转换为Pdf。 after a few minutes searching I found
几分钟后,我找到了
https://www.nuget.org/packages/Rotativa/ https://www.nuget.org/packages/Rotativa/
and 和
https://www.nuget.org/packages/RazorPDF https://www.nuget.org/packages/RazorPDF
both give me the same problem that will be explained below: 两个都给我同样的问题,将在下面解释:
I installed Rotativa 1.6.1 via nuget in a Mvc4 project. 我在Mvc4项目中通过nuget安装了Rotativa 1.6.1。
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. 当我使用浏览器访问操作方法时,我得到以下结果。
any Idea on why the pdf is not being shown? 关于为什么不显示pdf的任何想法?
this same error happens when I try with RazorPDF. 当我尝试使用RazorPDF时会发生同样的错误。
I had the same problem with asp.net mvc 4 and Rotativa. 我对asp.net mvc 4和Rotativa也有同样的问题。 Adding a binding redirect for System.Web.Mvc in my web.config solve the problem for me.
在我的web.config中为System.Web.Mvc添加绑定重定向为我解决了这个问题。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.