use*_*202 0 pdf ajax asp.net-mvc jquery
我有一个ajax请求apiurl我在哪里得到一个PDF文件.现在我想在新窗口中显示此文件
$("#pdfurl").click(function (e) {
var Pdfurl = $(this).attr('data-href');
$.ajax({
url: "../RequestPages/PreviewPdf",
type: "GET",
data: { "pdfUrl": Pdfurl },
success: function (data) {
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
})
public ActionResult PreviewPdf(string pdfUrl)
{
var web = new WebClient();
byte[] bytes = web.DownloadData(pdfUrl);
string mimeType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline; filename=" + "a.pdf");
return File(bytes, mimeType);
}`
Run Code Online (Sandbox Code Playgroud)