【发布时间】:2018-12-19 12:39:31
【问题描述】:
我使用rotativa 在asp net core 2.0 中生成pdf 视图。
生成效果很好,我的疑问是关于响应。如果我使用这个代码块工作,当我点击按钮时它会自动下载:
@using (Html.BeginForm(null, null, FormMethod.Get, new { @action = action , @class="block"}))
{
<button type="submit">Send</button>
}
但我需要通过ajax 发送请求。它也可以,但是我不知道在返回数据时如何下载文件。例如,按照ajax 请求:
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');
}
});
}
这是我用来在服务器中生成的代码:
return new ViewAsPdf(view, obj) { FileName = product + ".pdf" };
【问题讨论】:
标签: javascript c# ajax asp.net-mvc asp.net-core