3

I'm using rotativa for generate view to pdf in asp net core 2.0.

It works fine to generate, my doubt is about response. If I use this block of code works, it automatically do download when I click button:

@using (Html.BeginForm(null, null, FormMethod.Get, new { @action = action , @class="block"}))
{
    <button type="submit">Send</button>
}

But I need to send the request by ajax. It works too, but I don't know how to download file when the data is returned. For example, follow the ajax request:

function pdf() {
    $.ajax({
        type: "GET",
        url: url,
        data: {
            'Id': Id,
            'p': p
        },
        beforeSend: function () {
            console.log('Wait...');
        },
        success: function (data) {
            console.log('Success! (I need to download file here)')
        },
        error: function (data) {
            alert('error');
        }
    });
}

Here is the code I'm using to generate in server:

return new ViewAsPdf(view, obj) { FileName = product + ".pdf" };
CKE
  • 1,533
  • 19
  • 18
  • 29
Fabio Alves
  • 91
  • 1
  • 10

1 Answers1

1

It is already answered here

You can create an anchor element on the fly and click it programmatically or use Download js

Jawahar
  • 117
  • 7