我使用Kendo Grid作为我的ASP.NET MVC应用程序,它使用ajax绑定进行读取 . 它将数据绑定到第一页,但不显示网格的页码 . 它显示(| <0>> |) .
Index.cshtml
@(Html.Kendo().Grid<Club.Areas.Admin.Models.Users>()
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("List1", "Home"))
.PageSize(5)
)
.Columns(columns =>
{
columns.Bound(p => p.Id).Filterable(false).Width(100);
columns.Bound(p => p.NickName).Width(100);
columns.Bound(p => p.UserVisitLastDate).Format("{0:MM/dd/yyyy}").Width(140);
columns.Bound(p => p.Mobile).Width(100);
})
.Pageable()
.Sortable()
.HtmlAttributes(new { style = "width:500px;height:430px;" })
)
HomeController
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult List1([DataSourceRequest]DataSourceRequest request)
{
List<Users> U = new List<Users>();
for (int i = 0; i < 100; i++)
{
U.Add(new Users
{
NickName = "Mehdi",
Company = "Taral",
Email = "[email protected]",
Family = "FT",
HomeAddress = "Isfahan",
HomePhone = "03112332940",
IsActive = true,
Mobile = "09131025834",
Name = "Mehdi",
UserCreateDate = DateTime.Now,
UserVisitLastDate = DateTime.Now,
WebSite = "",
WorkAddress = "Mehdi",
PostalCode = "1234567890",
Id = i,
WorkPhone = "03117726250"
});
}
DataSourceResult result = U.ToDataSourceResult(request);
return Json(result,JsonRequestBehavior.AllowGet);
}
}
2 回答
您必须设置DataSource的
serverPaging: true
并确保来自服务器的响应具有包含项目数量的总字段 .我的答案与MVC方法并不完全相关,我已将其与WebAPI控制器一起使用 . 数据源应如下所示:
模式中的总属性是获取记录总数的位置,并计算要显示的页数 . 在您的情况下,您正在接收第一页的数据,并且网格不知道有多少数据来计算需要的总页数 .