用于MVC导出到Excel的Kendo UI Grid不执行任何操作

时间:2015-04-15 21:19:21

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

我正在使用Kendo网格进行MVC 4.0。我有最新的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")))
)

控制器

    [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"));

4 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:1)

我的问题与音量有关 - 记录数量较少,大批量则没有。我目前的解决方法是设置AllPages(false),然后它将只导出一个已过滤的列表。见http://www.telerik.com/forums/excel-export-not-working-with-more-than-a-thousand-records

答案 2 :(得分:0)

根据文档,我认为你需要这样做。

控制器

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

        return File(fileContents, contentType, fileName);
    }

CSHTML

 .Excel(excel => excel
    .FileName("Enrollments.xlsx")
    .Filterable(true) //omit this if you don't need filtering in excel
    .ProxyURL(Url.Action("Excel_Export_Save", "Grid")) // for browsers not supporting saving file from JS
 )

请参阅演示代码here,有关文档,请参阅此link

答案 3 :(得分:0)

我刚才遇到了同样的问题 - 导出按钮什么都不做。我正在运行2014年第3版的剑道。

升级到最新的DLL并更新到最新的JavaScript库和样式为我修复了这个。