This is a migrated thread and some comments may be shown as answers.

How to render report from ajax call?

1 Answer 605 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aubrey Ivan
Top achievements
Rank 1
Aubrey Ivan asked on 20 Nov 2019, 01:43 AM

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?

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 22 Nov 2019, 03:34 PM

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
Tags
General Discussions
Asked by
Aubrey Ivan
Top achievements
Rank 1
Answers by
Neli
Telerik team
Share this question
or