【发布时间】:2016-09-01 15:25:17
【问题描述】:
我是 KendoUI 的新手,所以这似乎是一个菜鸟问题。
我正在尝试使用 KendoUI 和 Web API 实现服务器端分页。
这是我生成剑道网格的脚本
$(function () {
$("#grid").kendoGrid({
height: 400,
columns: [
"FirstName",
"LastName",
{ field: "Mobile", width: "150px" },
{ field: "Email", width: "150px" },
{ field: "LoginVerified", width: "150px" },
{ field: "DivisionName", width: "100px" }
],
pageable: true,
sortable: true,
filterable: true,
dataSource: {
serverPaging: true,
serverFiltering: true,
serverSorting: true,
pageSize: 10,
transport: {
read: "/api/Users/GetStaffsPaged"
}
}
});
});
这是我的 Web API 函数
[HttpGet]
[ActionName("GetStaffsPaged")]
public IEnumerable<StaffsBasicInfo> GetStaffsPaged()
{
var take = string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["take"]) ? 1000 : Convert.ToInt32(HttpContext.Current.Request.QueryString["take"]);
var skip = string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["skip"]) ? 1000 : Convert.ToInt32(HttpContext.Current.Request.QueryString["skip"]);
StaffsBasicInfoBL staffsBL = new StaffsBasicInfoBL();
List<StaffsBasicInfo> staffs = staffsBL.getAllStaffsBasicInfo();
staffs = staffs.Skip(skip).Take(take).ToList();
return staffs;
}
当我运行我的代码时,网格总是显示前 10 条记录,但我的数据库有 2000 多条记录。
我尝试了很多教程来解决这个问题,但我无法进行分页。
http://www.telerik.com/blogs/the-facts-on-using-kendo-ui-with-asp-net-webapi
根据上面的教程,我的代码应该可以工作了。
我也试过这个教程,但我的 Visual Studio 无法解析 DataSource 类。
http://blog.falafel.com/server-paging-sorting-filtering-kendo-datasourcerequest/
请帮我实现分页
【问题讨论】:
标签: asp.net asp.net-web-api kendo-ui pagination