我有一个带有 Jquery Post 的 MVC 应用程序
$.post(virtualPath + cookie + this.pageName + '/FunctionA/', parameters,function (filedata) {
alert(filedata);
},'application/csv');
}
这篇文章是从 Javascript 事件中调用的,该事件由单击按钮触发以下载文件
我在警报中获得服务器端 Http 文件响应,但无法在浏览器中下载它
控制器将响应返回为 FileContentResult
[AcceptVerbs(HttpVerbs.Post)]
public FileContentResult FunctionA(string A, DateTime B)
{
try
{
string csv = "Make it downloadable ";
var filresult = File(new System.Text.UTF8Encoding().GetBytes(csv), "application/csv", "downloaddocuments.csv");
// return filresult;
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=Statement_" + "Downloadfile" + ".csv");
Response.Write(csv);
Response.Flush();
return filresult;
}
}