【问题标题】:Kendo Grid Paging doesn't work in Asp.Net MVC剑道网格分页在 Asp.Net MVC 中不起作用
【发布时间】:2014-03-28 02:28:41
【问题描述】:

我正在尝试在 Asp.Net MVC 中绑定 Kendo Grid,但分页不起作用。 PageSize 和 Total 记录是正确的,问题是无法导航到下一页。所有按钮都显示,但它们被禁用。

视图的代码是:

<% Html.Kendo().Grid(Model)
        .Name("PartListGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.Id).Title("Id").Visible (false);
            columns.Bound(p => p.Quantity).Title("Quantity")).Width(130);
            columns.Bound(p => p.PartNumber).Title("Part Number").Width(130);
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(p=>p.Id))
            .PageSize(5)
            .ServerOperation(false)
        )
        .Pageable()
        .Render();                                        
%>

控制器的代码:

public ActionResult GetPartListInfo(string id)
{                 
    List<PartListViewModel> partList = new List<PartListViewModel>();
    XrmServiceContext xrmServiceContext = new XrmServiceContext();
    f1_workorder workOrder = xrmServiceContext.f1_workorderSet.Where(i => i.Id == new Guid(workOrderId)).FirstOrDefault();
    PartListViewModel partViewModel = null;

    foreach (f1_workorderproduct workorderproduct in xrmServiceContext.f1_workorderproductSet.Where(i => i.f1_WorkOrder.Id == workOrder.Id).ToList())
    {
        Product product = xrmServiceContext.ProductSet.Where(j => j.Id == workorderproduct.f1_Product.Id).FirstOrDefault();

        partViewModel = new PartListViewModel();
        partViewModel.Id = workorderproduct.f1_Product.Id.ToString();  
        partViewModel.Quantity = workorderproduct.f1_EstimateQuantity.GetValueOrDefault(0);
        partViewModel.PartNumber = workorderproduct.f1_name;                              

        partList.Add(partViewModel);     
    }    

    return View("PartList",partList);
}

感谢任何建议! 非常感谢您的帮助!

咪咪

【问题讨论】:

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


    【解决方案1】:

    我敢打赌,您必须添加数据源读取配置,以便数据集可以在需要时获取分页数据。

    .DataSource(dataSource => dataSource
        ...
        .Read(read => read.Action("YourAction", "YourController))
        ...
    

    【讨论】:

    • 使用 F12 检查您的 ID 字段,查看请求中是否使用了 ID。我敢打赌,可能不会发送。
    • 我不认为这行是必需的 .Model(model => model.Id(p=>p.Id)) 。只有在使用更新/插入/删除命令时才需要的网格。
    • 嗨,谢谢你的回答,但是当我从 Controller .Read(read => read.Action("GetParts", "Claim", new { id = Model.WoId }) 调用方法时,我在网格中看不到任何东西;网格未绑定,因为我无法像以前那样在参数中传递模型:() .Name("PartListGrid")...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多