FastReport icon indicating copy to clipboard operation
FastReport copied to clipboard

Using FastReport OpenSource Web in DotNet Core with Partialview, Report not rendered, Showing Loading Icon only

Open VaskarBanerjee opened this issue 5 years ago • 4 comments

I am using SQL Server with DotNet Core. Trying to show FastReport inside Pertial View. Report not working, just showing loading icon and toolbar only. Below I am attaching my Code.

** Main View (Index.cshtml) **

<button id="btnPrint" class="btn btn-outline-info btn-sm font-weight-bold" accesskey="P" data-toggle="modal"  data-target="#dvPrnModal" title="Print Record (Alt + P)" style="width:60px;"><strong style="color:red;"><u>P</u></strong>rint</button>
<div id="dvPrnModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="printModal" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-xl" role="document" style="width:1500px; height:700px;">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="exampleModalLongTitle">Print Subscription Receipts</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body" style="padding: 15px 15px 5px 15px; min-height: 600px; max-height: calc(100vh - 212px); overflow-y: auto;">
                <div class="form-group row">
                    <div class="col-lg-12">
                        <div id="partial">
                            @{await Html.RenderPartialAsync("~/Views/Shared/ViewReport.cshtml");}
                        </div>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- form-group row -->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<!-- Print Preview Modal End -->

** Script Section **

$("#btnPrint").click(function (e) {
   // Home is your controller, Index is your action name
    $("#partial").load("/Subscriptions/ViewReport", { vEntryID: $("#EntryID").val(), viewName: "ViewReport" },
        function (response, status, xhr) {
            if (status == "error") {
                alert("An error occurred while loading the results.");
                return;
            }
});

** Controller Action **

    [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
    public virtual ActionResult ViewReport(string vEntryID)
    {
        WebReport webreport = new WebReport();

        try
        {
            webreport.Report.Load(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot//FastReports", $"{ reportToLoad}.frx"));
            webreport.Report.SetParameterValue("ConnectionString", DBConnectionString);
            webreport.Report.SetParameterValue("pEntryID", vEntryID);

            var dataSet = new DataSet();
            dataSet = _Subscription.PrintSubscription(vEntryID); //
            webreport.Report.RegisterData(dataSet, "rptSubscription");
            webreport.Report.GetDataSource("rptSubscription").Enabled = true;
            webreport.Report.Prepare();
            ViewBag.WebReport = webreport; // pass the report to View
        }
        catch (Exception ex)
        {  }
        return PartialView("ViewReport", ViewBag.WebReport);
    }

** Partial View (ViewReport.cshtml) **

@if (ViewBag.WebReport != null) { @await ViewBag.WebReport.Render() }

*** Output Screen Shot ***

image

VaskarBanerjee avatar May 05 '21 17:05 VaskarBanerjee

As showing 19 Pages in report but data not showing. Only Loading Icon.

image

VaskarBanerjee avatar May 06 '21 06:05 VaskarBanerjee

This pice of code is not god idea: } catch (Exception ex) { } return PartialView("ViewReport", ViewBag.WebReport);

I observe similar behavior in case of errors when initializing the report. Set a breakpoint in initialization code of report and see what going wrong.

public async Task<IActionResult> Index(string Token, Guid AId, bool APreview, TParam1 AParam) { //some code.. if (!await _userModel.SetToken(Request.Headers)) return Problem("Request Header Token value not found."); if (APreview) { try { var vReport = _ReportModel.GetReport(AId, WebReportMode.Preview, AParam); ViewBag.Report = vReport; return PartialView("ReportPreview"); } catch (Exception ex) { return Problem($"Index(AId={AId}, APreview={APreview})\n" + ex.Message + "\n" + ex.StackTrace); } } else return File("~/DesignerPages/DataSetPage.html", "text/html"); }

ReportPreview.chtml content: ` @model ReportModel;

@if (ViewBag.Report != null) @await ViewBag.Report.Render() `

RedKot73 avatar May 06 '21 06:05 RedKot73

Your feedback is not clear. Please explain in detail.

Regards,

VaskarBanerjee avatar May 06 '21 07:05 VaskarBanerjee

Hello!

In the latest version this problem is not reproduced

Best regards Marat

MaratAlaev avatar Mar 30 '23 13:03 MaratAlaev