asp.net-mvc – 导出Excel文件以查看(MVC)
发布时间:2020-05-27 07:39:13 所属栏目:asp.Net 来源:互联网
导读:我必须将数据导出为Excel,实际上我已实现,但我怀疑是什么时候 使用 return new FileContentResult(fileContents, application/vnd.ms-excel); VS return File(fileContents, application/vnd.ms-excel); 以及如何在每种方法中设置可下载的文件名? 例1: publ
|
我必须将数据导出为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-mvc – 带有Expression Web 4的ASP.NET MVC(RAZOR)
- asp.net – 3层架构 – 需要一个例子
- asp.net-core – .net core(csproj)global.json’projects’
- asp.net-mvc – 解耦Microsoft.AspNet.Identity.*
- asp.net-mvc-4 – 工作单元和通用存储库与实体框架5
- ASP.NET Web Forms 4.5模型绑定,其中模型包含一个集合
- asp.net-mvc-4 – 基于角色的导航
- asp.net-mvc – 具有Fluent nHibernate和Ninject的多租户.每
- asp.net-mvc – 在Controller或其他地方渲染部分字符串
- 禁用ASP.NET HttpHandler响应缓存
推荐文章
站长推荐
- asp.net-mvc-4 – 使用WebApi和外部登录的ASP.NE
- asp.net-mvc-3 – Elmah和ASP.NET MVC 3
- asp.net-mvc-3 – DropDownListFor中的ViewBag属
- 实体框架 – 带有实体框架的MVC 3和ASP.Net脚手架
- 当ASP.NET验证失败时,更改文本框的css类
- asp.net – ‘txtName’未声明 由于其保护等级可
- asp.net – aspnet_compiler找到错误版本的Syste
- 如何在ASP.NET Core 2.0中设置多个身份验证方案?
- .net – 编辑器模板不适用于DisplayFormat
- asp.net-mvc-3 – 删除Razor MVC 3中的HTML格式
热点阅读
