MVC 导出Execl 的总结几种方式 (四)

 这种方式我个人还是比较喜欢的,使用部分视图的方式,导出Execl 这样在编辑样式上也是很方便的

 

第一步: 编辑导出视图页

 

@using H5UpdateImage.Models;
@{
    Layout = null;
    Response.AddHeader("Content-disposition", "attachment;filename=Order.xls");
}

@model List<Order>
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ExeclIndex</title>
    <style type="text/css">
        .ltable th {
            padding: 8px 0;
            color: #333;
            font-size: 12px;
            font-weight: 500;
            background: #f3f3f3;
            border-bottom: 1px solid #E1E1E1;
            line-height: 1.5em;
        }

        .ltable th, .ltable td {
            border: 1px solid #e1e1e1;
            text-align: center;
        }

        .ltable th {
            padding: 8px 0;
            color: #333;
            font-size: 12px;
            font-weight: 500;
            background: #f3f3f3;
            border-bottom: 1px solid #E1E1E1;
            line-height: 1.5em;
        }
    </style>

</head>
<body>
    <table class="ltable">
        <thead>
            <tr>
                <th> 订单编号</th>
                <th>订单来源</th>
                <th>会员姓名</th>

            </tr>
        </thead>
        <tbody class="ltbody">
            @foreach (var item in Model)
            {
                <tr>
                    <td>@item.Id</td>
                    <td>@item.Name</td>
                    <td>@item.CreateTime</td>
                </tr>
            }
        </tbody>
    </table>
</body>
</html>
View Code

 

 第二步: 控制代码

  /// <summary>
        /// MVC 内置视图导出Execl
        /// </summary>
        /// <returns></returns>
        public ActionResult ExeclIndex()
        {
            var list = GetList();


            return View(list);
        }

第三步: 触发导出 代码

 <a id="btnExport" href="javascript:ExportData();void(0);">导出</a>

js代码
 function ExportData() {
       
        window.open('@Url.Action("ExeclIndex")');
    }

 

转载于:https://www.cnblogs.com/lizichao1991/p/5788073.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值