asp.net-mvc – 导出Excel文件以查看(MVC)
发布时间:2020-12-15 20:57:08 所属栏目:asp.Net 来源:网络整理
导读:我必须将数据导出为Excel,实际上我已实现,但我怀疑是什么时候 使用 return new FileContentResult(fileContents,"application/vnd.ms-excel"); VS return File(fileContents,"application/vnd.ms-excel"); 以及如何在每种方法中设置可下载的文件名? 例1: p
我必须将数据导出为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"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET Core 企业开发架构概述
- asp.net-mvc – 为什么UserManager.CreateIdentityAsync()正
- 依赖性 – 安装RavenDb Embedded的Nuget依赖性错误
- asp.net – MVC 3/4 HttpModule或ActionFilter
- asp.net – 如何设置sqldatasource参数的值?
- 以编程方式或声明性地要求IIS中的单个asp.net页面的客户端证
- asp.net-mvc – MapMvcAttributeRoutes:此方法不能在应用程
- asp.net-mvc – Angular ng-include cshtml页面
- asp.net-mvc-3 – 有没有办法通过html.actionlink在ASP.NET
- asp.net-mvc – MultiSelect jqgrid MVC3的OnClickButton函