问题描述
我正在使用Rotativa(版本1.6.3)从我的角度生成pdf.我有一个简单的局部视图(_OverallResultPrintVersion.cshtml):
I am using Rotativa (version 1.6.3) to generate pdf from my view. I have a simple partial view(_OverallResultPrintVersion.cshtml):
@Styles.Render("~/bundles/css")
<img src="@Url.Action("DrawChart", "Vote", new {area = "Award"})"/>
在我的操作中,当返回Rotativa PartialViewAsPdf时,它会打开一个空白的pdf页面,并且不会按预期方式调用"DrawChart"操作.这是我在表决控制器中实现我的操作的方式:
In my action when returning Rotativa PartialViewAsPdf, it opens an empty pdf page and the "DrawChart" action won't be called as expected.Here is how I implemented My actions in Vote controller:
public ActionResult OverallResultPdf()
{
return new Rotativa.PartialViewAsPdf(
@"~\Areas\Award\Views\Shared\Widget\_OverallResultPrintVersion.cshtml");
}
public ActionResult DrawChart()
{
var model = getModel();
return PartialView("Widget/_VotesColumnChart", model);
}
将局部视图中的图像源替换为网址"时,它会显示图像,但这不是我要实现的目标.知道为什么Rotativa PartialViewAsPdf无法从局部视图调用我的操作吗?
When replacing the image source in partial view to an Url, it shows the image but this is not what I'm trying to achieve.Any idea why Rotativa PartialViewAsPdf cannot call my action from partial view?
PS:这些操作没有授权限制,因此在创建PartialViewAsPdf时不需要初始化FormsAuthenticationCookieName属性.
PS: there is no authorization restriction for these actions so I don't need to initiate FormsAuthenticationCookieName property when creating PartialViewAsPdf.
推荐答案
这是解决此问题的解决方法.花费一个新的动作吧! (OverallResultPrintVersion)并在TotalResultPdf操作中,需要返回ActionAsPdf而不是返回PartialViewAsPdf.
here is a workaround to resolve the issue. It costs adding a new Action! (OverallResultPrintVersion) and in OverallResultPdf action, instead of returning PartialViewAsPdf, an ActionAsPdf needs to be returned.
public ActionResult OverallResultPdf()
{
return new Rotativa.ActionAsPdf("OverallResultPrintVersion");
}
public ActionResult OverallResultPrintVersion()
{
return PartialView("Widget/_OverallResultPrintVersion");
}
和DrawChart()操作保持不变.
and DrawChart() action remains untouched.
这篇关于未从Rotativa PartialViewAsPdf调用MVC操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!