mvc action not being called from Rotativa PartialViewAsPdf

浪子不回头ぞ 提交于 2020-01-06 19:33:38

问题


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"})"/>

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);
}

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: there is no authorization restriction for these actions so I don't need to initiate FormsAuthenticationCookieName property when creating PartialViewAsPdf.


回答1:


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");
}

and DrawChart() action remains untouched.



来源:https://stackoverflow.com/questions/29268449/mvc-action-not-being-called-from-rotativa-partialviewaspdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!