大家好奇,如果有人可以帮忙;我写了这个代码,它将生成一个Excel电子表格并将其保存到指定的位置。然后,我想通过从存储位置读取文件来显示“另存为”对话框,然后询问用户他们想要存储它的位置。 Excel文件生成正常,我可以正常打开它!然而,我的问题是我写的代码似乎是直接将文件输出到我的浏览器,所以我得到了我的浏览器屏幕上的Excel文件的所有内容,不像预期的那样显示保存为对话框!MVC C#下载文件并另存为对话框
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");
}