将 Excel 文件导出到视图 (MVC)
我必须导出数据以Excel形式查看,实际上我已经实现了,但我的疑问是什么时候 使用
return new FileContentResult(fileContents, "application/vnd.ms-excel");
与
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");
}
I have to Export Data to View as Excel , Actually I have Implemented,but my doubt is when
to use
return new FileContentResult(fileContents, "application/vnd.ms-excel");
vs
return File(fileContents, "application/vnd.ms-excel");
and How can set Downloadable Filename in each of this methods?
Example 1:
public ActionResult ExcelExport()
{
byte[] fileContents = Encoding.UTF8.GetBytes(data);
return new FileContentResult(fileContents, "application/vnd.ms-excel");
}
Example:2
public ActionResult ExcelExport()
{
byte[] fileContents = Encoding.UTF8.GetBytes(data);
return File(fileContents, "application/vnd.ms-excel");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以阅读有关 FileContentResult 和 FileContentResult 之间的差异的信息。此处的 FileResult : 之间有什么区别ASP.NET MVC 中的四个文件结果
您可以像这样指定文件名
You can read about the differences between FileContentResult & FileResult here : What's the difference between the four File Results in ASP.NET MVC
You can specify the filename like this