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?