How to render report from ajax call?

2 posts, 0 answers
  1. Aubrey Ivan
    Aubrey Ivan avatar
    26 posts
    Member since:
    Oct 2019

    Posted 19 Nov 2019 Link to this post

    I am using MVC report viewer along with asp.net mvc ui and I want to generate a report after an ajax call

    here is my ajax

    <script>
        function generateAccountsPayableReports() {
            var ms = $("#msInvoicesAPV").data("kendoMultiSelect");
            var invoices = ms.dataItems();
            var invoiceIds = [];

            invoices.forEach(function (invoice) {
                invoiceIds.push(invoice.Id);
            });

            $.ajax({
                type: "POST",
                url: "/APV/GenerateData ",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({ 'invoiceIds': invoiceIds }),
                success: function (result) {
                    if (result) {
                        console.log("Result: ", result);
                        var w = window.open();
                        $(w.document.body).html(result);
                    }
                },
                failure: function (result) {
                    console.error("result: ", result);
                },
                error: function (result) {
                    console.error("result: ", result);
                }
            });
        }
    </script>

    and here is my controller action

            [HttpPost]
            public ActionResult GenerateReport(List<Guid> invoiceIds)
            {
                var apvReports = _reportsLogic.GenerateAccountPayableVouchers(invoiceIds);
                string json = JsonConvert.SerializeObject(apvReports);
                string reportSource = typeof(AccountsPayableVoucher).AssemblyQualifiedName + "--" + json;

                return View("CustomReportViewer", (object)reportSource);
            }

     

    I tried initializing a new window and assigning the html to that window but if failed as you can see in my ajax call

                        var w = window.open();
                        $(w.document.body).html(result);

    is there other way you could advise me to?

  2. Neli
    Admin
    Neli avatar
    255 posts

    Posted 22 Nov 2019 Link to this post

    Hi Aubrey,

    We need to have more details about the issue and the error to be able to provide any suggestions or information. Can you send us some screenshots of the error?

    In addition, I would suggest to check our HTML5 MVC demo which can be found in the installation folder of Telerik Reporting:

    C:\Program Files (x86)\Progress\Telerik Reporting <Version>\Examples\CSharp

     

    Regards,
    Neli
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top