HttpContext.JsReportFeature() returns null
-
Hello,
I am trying jsreport in ASP.NET Core 2.1 Razor pages. I am following the example given at
https://github.com/jsreport/jsreport-dotnet-example-webapp/blob/master/Controllers/HomeController.cs#L26.I have a similar method on my Razor Page
public class IndexModel : PageModel
{
public void OnGet()
{} [MiddlewareFilter(typeof(JsReportPipeline))] public IActionResult OnPostGeneratePdf() { HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf); return Page(); } }
The problem is that HttpContext.JsReportFeature() is null and I get an object reference error. I already added the required code in startup.cs.
The sample app provided at https://github.com/jsreport/jsreport-dotnet-example-webapp runs perfectly fine locally. The only difference is that the sample app is MVC based with Model-View-Controllers whereas I am using the Razor Pages.
Appreciate any help on this.
Thank you
-
You can try to debug it
https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportMiddleware.cs#L21However I am afraid MiddlewareFilter is not invoked in razor pages.
-
If MiddlewareFilter is not invoked probably that is the reason.
Does that mean, I cannot generate for e.g. pdf reports if I am using Razor Pages? Does jsreport only work on MVC projects?
-
I don't know. There is likely a way how to get html string from the razor page which you can afterwards easily convert into pdf using jsreport.
Unfortunately I am too busy to investigate this and I never used razor pages before.If you find out how to get the html string form the razor page, you can use this code to convert it to the pdf.
var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create(); var report = await rs.RenderAsync(new RenderRequest() { Template = new Template() { Recipe = Recipe.PhantomPdf, Engine = Engine.None, Content = "The html you get from the razor page" } });