在我的 ASP.NET MVC 项目中,我使用ClosedXML生成了一个 excel 文件。
它在非 ajax 调用中运行良好。这是我的控制器操作方法
// Prepare the response
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=\"" + reportHeader + ".xlsx\"");
// Flush the workbook to the Response.OutputStream
using (MemoryStream memoryStream = new MemoryStream())
{
MyWorkBook.SaveAs(memoryStream);
memoryStream.WriteTo(Response.OutputStream);
memoryStream.Close();
}
Response.End();
现在我正在尝试通过 ajax 请求来做到这一点。但是文件不是从 mvc 控制器发送的。
$.ajax({
url: url,
type: "POST",
data: fd,
processData: false,
contentType: false,
beforeSend: function () {
},
success: function (response) {
},
error: function (request, status, error) {
},
complete: function () {
}
});
我怎样才能完成它?先感谢您。