//returning File Response in Controller action Method
return File(MyMemoryStream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "lp.xlsx");
我想下载这个文件,但我已经使用ajax从视图传递数据到控制器,所以它返回到ajax成功函数。
<script>
$(".pfamlink").click(function()
{
$.ajax({
type: "GET",
url: "/Home/Excel",
data: { "data":$(this).html()},
success: function(response)
{}
});
});
</script>
我需要在这个函数(响应)中给出从控制器下载返回的文件?
或任何建议传递表数据从视图到控制器没有Ajax ?
我需要在这个函数(响应)中给出下载返回文件来自控制器?
FileContentResult返回给Ajax成功函数,下载失败是因为我们需要成功操作。尝试添加一个下载操作,使用window.location
重定向到控制器中的下载操作。
public async Task<IActionResult> DownloadAsync()
{
...
//returning File Response in Controller action Method
return File(MyMemoryStream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "lp.xlsx");
在ajax成功后,像下面这样修改代码:
success: function (data) {
window.location = '/yourcontrollername/Download';
}