分页不起作用 [英] Pagination does not work

查看:212
本文介绍了分页不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剑道MVC格所在的分页不起作用。它装载在结果集的单个页面,然后点击页面按钮没有做任何事情。

I've got a Kendo MVC Grid where the pagination does not work. It's loading the resultset in a single page, and clicking the page buttons does not do anything.

该脚本文件正确,并在正确的顺序( jQuery的-1.11.2.min.js kendo.all.min加载。 JS kendo.aspnetmvc.min.js )。

The script files are loaded correctly and in the right order (jquery-1.11.2.min.js, kendo.all.min.js and kendo.aspnetmvc.min.js).

我使用的是剑道UI版本2015年Q1(2015.1.318.545)。

I'm using Kendo UI version 2015 Q1 (2015.1.318.545).

查看

@(Html.Kendo().Grid<MyModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(c => c.Type);
        columns.Bound(c => c.Count);
        columns.Bound(c => c.Date);
    })
    .Filterable()
    .Pageable(pageable => pageable
        .Refresh(true)
        .PageSizes(true)
        .ButtonCount(10)
        .PageSizes(new[] { 20, 50, 100 }))
    .DataSource(ds => ds
        .Ajax()
        .Read(r => r.Action("GetGridData", "Home", new { code = "code" }))
        .PageSize(20)
    )
)

控制器

public ActionResult GetGridData([DataSourceRequest]DataSourceRequest request, string code = "")
{
    var result = MyService.GetGridData(code);
    return Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

服务

public IQueryable<MyModel> GetGridData(string code) 
{
    using (var dbContext = new MyEntities())
    {
        return dbContext.Products.Where(w => w.Code == code)
                                 .Select(s => new MyModel {
                                     Type = s.Type,
                                     Count = s.Count,
                                     Date = s.Date
                                 });
    }
}

在加载页面时,DataSourceRequest看起来是这样的:

When loading the page, the DataSourceRequest looks like this:

没有适当的页大小的结果是完整的数据集,因为在这里看到:

Without a proper page size the result is the full dataset, as seen here:

推荐答案

我最终加入。键入(HttpVerbs.Get)来read方法将其固定。我不知道为什么这能解决问题,因为它已经在做一个GET。随着。键入(HttpVerbs.Get)得当添加 DataSourceRequest 参数的URL。

I ended up fixing it by adding .Type(HttpVerbs.Get) to the read method. I have no idea why this fixes the issue, because it was already doing a Get. With .Type(HttpVerbs.Get) it properly adds the DataSourceRequest parameters to the url.

@(Html.Kendo().Grid<MyModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(c => c.Type);
        columns.Bound(c => c.Count);
        columns.Bound(c => c.Date);
    })
    .Filterable()
    .Pageable(pageable => pageable
        .Refresh(true)
        .PageSizes(true)
        .ButtonCount(10)
        .PageSizes(new[] { 20, 50, 100 }))
    .DataSource(ds => ds
        .Ajax()
        .Read(r => r.Action("GetGridData", "Home", new { code = "code" }).Type(HttpVerbs.Get))
        .PageSize(20)
    )
)

这篇关于分页不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆