从ASP.NET MVC将HTML表导出到Excel [英] Exporting a HTML Table to Excel from ASP.NET MVC

查看:170
本文介绍了从ASP.NET MVC将HTML表导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用ASP.NET MVC,并且我有一个操作方法,该操作方法以表格式在视图中显示很少的报告.

I am currently working with ASP.NET MVC and I have an action method that displays few reports in the view in table format.

我需要单击视图中的一个按钮,将同一表导出到Excel文档.

I have a requirement to export the same table to an Excel document at the click of a button in the View.

如何实现?您将如何为此创建Action方法?

How can this be achieved? How would you create your Action method for this?

推荐答案

在您的控制器操作中,您可以添加以下内容:

In your controller action you could add this:

Response.AddHeader("Content-Disposition", "filename=thefilename.xls");
Response.ContentType = "application/vnd.ms-excel";

然后将用户发送到同一视图.那应该起作用.

Then just send the user to the same view. That should work.

这篇关于从ASP.NET MVC将HTML表导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆