Ajax将Kendo Grid绑定到Asp.Net MVC并不显示任何内容

时间:2014-03-30 02:00:05

标签: asp.net ajax binding kendo-ui kendo-grid

我正在尝试使用Asp.Net MVC绑定一个Kendo Grid。我在详细页面中显示网格查看与许多其他字段... 记录正确,但网格中没有显示任何内容。

以下是View:

的用户控件(ascx)中的网格代码
<% Html.Kendo().Grid<Web.Areas.WorkOrder.ViewModels.PartListViewModel>()
  .Name("Grid")
  .Columns(columns =>
  {
   columns.Bound(p => p.GlassType);
   columns.Bound(p => p.WorkType);
   columns.Bound(p => p.PartNumber);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetPartListInfo", "Claim", new { id = Model.JobId }))
.PageSize(5)
.ServerOperation(false)
)
 .Pageable()
 .Sortable()
 .Groupable()
 .Filterable()
 .Render();                                  
%>

模型视图如下所示:

    public IEnumerable<PartListViewModel> PartList { get; set; }
    public string VIN { get; set; }
    public string Invoice { get; set; }
    public string MileageKM { get; set; }
    public EntityModel Provider { get; set; }
    public string Comments { get; set; }
    …etc, etc

这是我的控制器代码:

public ActionResult GetPartListInfo([DataSourceRequest] DataSourceRequest request, string id)
    {
        XrmServiceContext xrmServiceContext = new XrmServiceContext();
        workorder workOrder = xrmServiceContext.workorderSet.Where(i => i.Id == new Guid(id)).FirstOrDefault();

        IEnumerable<PartListViewModel> parts = (xrmServiceContext.workorderproductSet.Where(prod => prod.WorkOrder.Id == workOrder.Id))
            .Select(x => new PartListViewModel
            {
                WOId = id,
                Id = x.f1_Product.Id.ToString(),
                Quantity = 3,
                PartNumber = "WS",,                    
                WorkType = "Repair", 
                GlassType = "Windshield",
                Price = 133
            }).ToList();

        return Json(parts.ToDataSourceResult(request));
    }

我在配置中遗漏了什么?我想知道它出了什么问题? 感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:1)

尝试添加此项以允许获取:

return Json(parts.ToDataSourceResult(request),JsonRequestBehavior.AllowGet);