如何使用Rotativa PDF获取Asp.Net MVC AREA的视图?

问题描述:

如何使用rotativa PDF在asp.net mvc区域中获取我的视图。在区域rotativa总是返回一个空白PDF。超出区域它工作正常。如何使用Rotativa PDF获取Asp.Net MVC AREA的视图?

我已经尝试:

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参数为我工作指定完整路径。不知道你的控制器是什么,我会认为它的“嗒嗒”

所以,如果你的.cshtml路线\区\管理\查看\布拉赫\ 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 } 
    }; 
}