Kendo Grid分页无法正常工作

时间:2015-03-20 13:46:52

标签: asp.net asp.net-mvc kendo-grid kendo-asp.net-mvc

我正在使用Kendo MVC网格。使用数据表而不是模型以网格显示。并根据页码填充数据。但是下面的分页不起作用是我的代码:

List.cshtml文件

@(Html.Kendo().Grid(Model)
.Name("UserGrid")
.EnableCustomBinding(true)
.Columns(columns=>
  { 
      foreach(System.Data.DataColumn column in Model.Columns)
      {
          columns.Bound(column.ColumnName).Title(column.Caption).Width(200);
      }
   }
)
.Selectable(selectable=>selectable
   .Type(GridSelectionType.Row)
)
.Pageable()
.Filterable()
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model =>
         {
             foreach(System.Data.DataColumn column in Model.Columns)
             { 
                 model.Field(column.ColumnName,column.DataType);
             }
         }
     )
      .Total((int)ViewData["recordcount"])
     .Read(read => read.Action("Read", "User").Type(HttpVerbs.Get))
 )
 )

这是Controller代码。 UserList函数将数据作为datatable和Read函数返回,以填充数据并通过grid:

传递
  private DataTable UserList()
    {
        DataSet ds = new DataSet();
        if (ViewData["pageno"] != null && Convert.ToInt16(ViewData["pageno"]) > 1)
        {
            iUserSearch.pageNumber = Convert.ToInt16(ViewData["pageno"]);
        }
        else
        {
            iUserSearch.pageNumber = 1;
        }
        iUserSearch.pageSize = 10;
        ds = iUser.ListUser(iUserSearch);
        var dataTable = new DataTable();

        dataTable = ds.Tables[0];
        if (ds.Tables[0].Rows.Count != 0 )
            ViewData["recordcount"] = (int)ds.Tables[0].Rows[0]["Totalcount"];
        return dataTable;

    }


    public ActionResult Read([DataSourceRequest] DataSourceRequest request)
    {
        //Paging and Sorting
        int currentPage = request.Page;
        int pageSize = request.PageSize;

        ViewData["pageno"] = currentPage;
        //Setting the TOTAL
        DataTable dt = UserList();
        //return View("List",dt);
        //var result = dt;
        return Json(dt.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

1 个答案:

答案 0 :(得分:0)

我已通过在视图

中指定模型ID来解决此问题