我必须将数据导出为Excel,实际上我已实现,但我怀疑是什么时候
使用
使用
return new FileContentResult(fileContents,"application/vnd.ms-excel");@H_404_5@VS
return File(fileContents,"application/vnd.ms-excel");@H_404_5@以及如何在每种方法中设置可下载的文件名? @H_404_5@例1:
public ActionResult ExcelExport() { byte[] fileContents = Encoding.UTF8.GetBytes(data); return new FileContentResult(fileContents,"application/vnd.ms-excel"); }@H_404_5@例如: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
@H_404_5@您可以像这样指定文件名
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");