@H_502_1@我必须将数据导出为Excel,实际上我已实现,但我怀疑是什么时候
使用
使用
return new FileContentResult(fileContents,"application/vnd.ms-excel");
VS
return File(fileContents,"application/vnd.ms-excel");
例1:
public ActionResult ExcelExport() { byte[] fileContents = Encoding.UTF8.GetBytes(data); return new FileContentResult(fileContents,"application/vnd.ms-excel"); }
例如:2
public ActionResult ExcelExport() { byte[] fileContents = Encoding.UTF8.GetBytes(data); return File(fileContents,"application/vnd.ms-excel"); }
解决方法
你可以阅读FileContentResult& FileResult:
What’s the difference between the four File Results in ASP.NET MVC
您可以像这样指定文件名
return new FileContentResult(fileContents,"application/vnd.ms-excel") { FileDownloadName = "name.xls" }; // or // note that this call will return a FileContentResult object return new File(fileContents,"application/vnd.ms-excel","name.xls");