Render View from another Area (MVC .Net Core)
-
Hi, I'm using MVC .net core and I have problems trying to specify the view to render which is in another (area) folder path
var contenido = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Areas/Cajas/Views/Cobros/DetailsPrint", cobroVM);
and I recive this exception:
ArgumentNullException: Value cannot be null.
Parameter name: Areas/Cajas/Views/Cobros/DetailsPrint does not match any available view
jsreport.AspNetCore.JsReportMVCService.RenderViewToStringAsync(HttpContext context, RouteData routeData, string viewName, object model)Is there any way to render a view from other area?
Thanks!
-
Do you have a full stack?
Or could you debug it here and find out what is actually null?
https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportMVCService.cs#L64
-
Hi, thanks for response.
I'm new in all of this and I don't know how to debug a NuGet package. So I copied the method RenderViewToStringAsync to my controller and also change the view namevar contenido = await RenderViewToStringAsync1(HttpContext, RouteData, "~/Areas/Cajas/Views/Cobros/DetailsPrint.cshtml", cobroVM);
The RenderViewToStringAsync method gives me null on viewResult
var viewResult = ((IRazorViewEngine)context.RequestServices.GetService(typeof(IRazorViewEngine))).FindView(actionContext, viewName, false);
Doing some research on internet in found many people have problem with FindView Method so I comment the line and add replace it with GetView method
//var viewResult = ((IRazorViewEngine)context.RequestServices.GetService(typeof(IRazorViewEngine))).FindView(actionContext, viewName, false); var hostingEnv = context.RequestServices.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment; var viewResult = ((IRazorViewEngine)context.RequestServices.GetService(typeof(IRazorViewEngine))).GetView(hostingEnv.WebRootPath, viewName, false);
and its works, but I don't know why FindView method give me null.
Any Suggestion?Thanks!
-
Thanks for sharing. I use now also
GetView
as suggested.
You can update jsreport.AspNetCore nuget, it is part of 2.0.2.Change for reference
https://github.com/jsreport/jsreport-dotnet-aspnetcore/commit/245018bc1a5b9aa02a261c81cf826bc13415a7b2