mvc action not being called from Rotativa PartialV

2019-09-11 10:44发布

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条回答
狗以群分
2楼-- · 2019-09-11 11:28

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.

查看更多
登录 后发表回答