How to display FastReport in Razor Pages

  below code i try to display FastReport in Razor Pages

  [BindProperty]

    public HomeModel model { get; set; }



 public IActionResult OnGet(int? reportIndex = 0)

    {

      model = new HomeModel()

      {

        WebReport = new WebReport(),

        ReportsList = new[]

       {

          "Simple List"

        },

      };

      var reportToLoad = model.ReportsList[0];

      if (reportIndex >= 0 && reportIndex < model.ReportsList.Length)

        reportToLoad = model.ReportsList[reportIndex.Value];

       var reportPath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "Reports");

      model.WebReport.Report.Load(System.IO.Path.Combine(reportPath, $"{reportToLoad}.frx"));

      var dataSet = new DataSet();

      dataSet.ReadXml(System.IO.Path.Combine(reportPath, "nwind.xml"));

      model.WebReport.Report.RegisterData(dataSet, "NorthWind");

      model.WebReport.Width = "1000";

      model.WebReport.Height = "1000";

      model.WebReport.Mode = WebReportMode.Preview;

      return Page();

    }

in View

  <div class="webreport">

    @await Model.model.WebReport.Render()

  </div>

Comments

  • Hello!

    To resolve your issue in Program.cs, please ensure you register `builder.Services.AddFastReport();` and call `app.UseFastReport();` before `app.MapRazorPages();`.

    Remove the [BindProperty] attribute from the WebReport property in the model if you are recreating it in OnGet(), and specify the Width and Height values with units (for example, “100%” / “800px”, or use the default values).

    After `webReport.Report.RegisterData(ds);`, explicitly enable tables (Enabled = true) if necessary, and check the path to Reports via `IWebHostEnvironment.ContentRootPath` / `WebRootPath`.

    If the report fails to render with an error, please send the full exception text and your `Program.cs` file.

This discussion has been closed.