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" };
It is already answered here
You can create an anchor element on the fly and click it programmatically or use Download js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.