asp.net-mvc - 用于 MVC 导出到 Excel 的 Kendo UI Grid 不执行任何操作

标签 asp.net-mvc excel export-to-excel kendo-asp.net-mvc

我正在使用 MVC 4.0 的 Kendo 网格。我有最新的 DLL 2015.1.318.440。我包括 jszip.js。我复制并粘贴了示例中的代码:

          .ToolBar(tools => tools.Excel())
          .Excel(excel => excel.FileName("Enrollments.xlsx"))

它什么也没做。按钮改变颜色,就是这样。当我尝试时,我没有收到任何错误。它只是没有做任何事情。我没有使用代理服务器。我在 Chrome 最新版本中运行它。

网格

@(Html.Kendo().Grid<Trawick.Agents.Models.EnrollmentPolicy>()
.Name("grid")
    .ToolBar(tools => tools.Excel())              
    .Excel(excel => excel
   .FileName("Enrollments.xlsx")
       .Filterable(true)
       .ProxyURL(Url.Action("Excel_Export_Save", "Enrollments"))
     )              
     .Columns(columns =>
      {
       columns.Bound(p => p.enrollment_date)
          })
     .Pageable()
     .Groupable()
     .Sortable()
     .DataSource(dataSource => dataSource
     .Ajax()
     .PageSize(20)
     .Read(read => read.Action("Enrollments_Read", "Enrollments")))
)

Controller

    [HttpPost]
    public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
    {
        var fileContents = Convert.FromBase64String(base64);

        return File(fileContents, contentType, fileName);
    }
    public ActionResult Enrollments_Read([DataSourceRequest]DataSourceRequest request, int? id)
    {
        string sql = "SELECT * FROM EnrollmentPolicy ";
        sql += SearchParams.SetSearch(this);
        return Json(GetEnrollments(sql).ToDataSourceResult(request));
    }

包含 jszip 的捆绑文件

bundles.Add(new ScriptBundle("~/js/kendo")
     .Include("~/Scripts/jszip.js")
     .Include("~/Scripts/kendo.all.min.js")
     .Include("~/Scripts/kendo.aspnetmvc.min.js"));

最佳答案

        bundles.Add(new ScriptBundle("~/js/kendo")
            .Include("~/Scripts/kendo.all.min.js")
            .Include("~/Scripts/kendo.aspnetmvc.min.js")
            .Include("~/Scripts/jszip.js"));

这就是问题所在。jszip 必须包含在 kendo 脚本之后(这与文档所说的相反)。

关于asp.net-mvc - 用于 MVC 导出到 Excel 的 Kendo UI Grid 不执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29661115/

相关文章:

jquery - 使用 Html.ValidationMessage 通过 jQuery 进行 ASP.NET MVC 客户端验证?

Excel 过滤合并单元格

excel - 查找前两行VBA的总和

excel - Grails:如何将 Grails 列表导出到 Microsoft Excel?

PHP导出excel unicode(俄语字符)问题

c# - 将 IEnumerable<T> 导出到 Excel

asp.net-mvc - MVC : How to make DropdownList field (with Chosen Plugin) Required

.net - 为什么 ValidateAntiForgeryTokenAttribute 允许匿名 token ?

c# - LINQ IQueryable 使用 skip 和 take 返回相同的行

excel - 从图表图例中删除系列并在 excel vba 中设置轴范围