【发布时间】:2020-02-27 21:09:46
【问题描述】:
我不确定是否是这样做的好方法。我想在新的浏览器选项卡中显示 PDF。
我有一个生成 MemoryStream 并返回到我的 ajax 调用的方法。这样做的好方法是什么?
我的 Ajax 调用:
$("#selector").click(function () {
urlToFunction = "/Controller/Function";
$.ajax({
url: urlToFunction,
data: ({ id: 12345 }),
type: 'GET',
success: function (response) {
???? here
},
error:
function (response) {
}
});
});
[HttpGet]
public async Task Print(int? id)
{
var ms = GETMemoryStreamPDF();
Response.ContentType = "application/pdf; charset=utf-8";
Response.Headers.Add("content-disposition", "attachment;filename=" + randomName + ".pdf;charset=utf-8'");
await Response.Body.WriteAsync(ms.GetBuffer(), 0, ms.GetBuffer().Length);
}
我的问题在这里:
success: function (response) {
???? here
},
在新标签中显示我的 PDF 的最佳做法是什么?
【问题讨论】:
标签: c# .net ajax asp.net-core-mvc