如何使用 Rotativa PDF 查看 Asp.Net MVC 区域?

How to use Rotativa PDF to get view on Asp.Net MVC AREA?

如何使用 rotativa PDF 在 asp.net mvc 区域中获取我的视图。在 Area rotativa 中总是 return 一个空白的 PDF。在区域外它工作正常。

我已经试过了:

  public ActionResult Report()
    {
        return new ViewAsPdf("Report") {
            FileName = "Report.pdf",
            PageSize = Size.A3,
            PageOrientation = Orientation.Portrait,
            PageMargins = { Left = 0, Right = 0 }
        };
    }

并且:

public ActionResult Report()
    {
        return new ViewAsPdf("Report", new { area  = "Admin" }) {
            FileName = "Report.pdf",
            PageSize = Size.A3,
            PageOrientation = Orientation.Portrait,
            PageMargins = { Left = 0, Right = 0 }
        };
    }

在 viewName 参数中指定完整路径对我有用。不确定你的控制器是什么,我假设它是 "Blah"

因此,如果您到 .cshtml 的路径是 \Areas\Admin\Views\Blah\Report.cshtml,则使用:

public ActionResult Report()
{
    return new ViewAsPdf("~\Areas\Admin\Views\Blah\Report.cshtml") {
        FileName = "Report.pdf",
        PageSize = Size.A3,
        PageOrientation = Orientation.Portrait,
        PageMargins = { Left = 0, Right = 0 }
    };
}