【发布时间】:2020-11-25 21:27:04
【问题描述】:
大家好,想知道是否有人可以提供帮助;我已经编写了这段代码,它将生成一个 Excel 电子表格并将其保存到指定位置。然后我想通过从存储位置读取文件然后询问用户他们想要存储它的位置来显示一个“另存为”对话框。 excel文件生成正常,可以正常打开!但是我的问题是我编写的代码似乎将文件直接输出到我的浏览器,所以我在浏览器屏幕上获取了 excel 文件的所有内容,没有按预期显示另存为对话框!
public ActionResult FormSuccess()
{
String FileName = System.Configuration.ConfigurationManager.AppSettings["FileName"].ToString();
String FilePath = System.Configuration.ConfigurationManager.AppSettings["FileSaveLocation"].ToString();
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "application/vnd.xls";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.TransmitFile(FilePath + FileName);
response.End();
return PartialView("FormSuccess");
}
【问题讨论】:
标签: c# asp.net-mvc