2015-11-06 122 views
0

我为我的剑道MVC网格创建了自定义数据源。 Everythink正在工作,数据正在从服务器回来。但是在网格中只显示空单元格。这样的形象: Empty cells 代码MVC格:MVC Kendo网格自定义数据源

  @(Html.Kendo().Grid<PageViewModel>() 
       .Name("pageGrid") 
       .Columns(columns => 
       { 
        columns.Bound(item => item.Name).Width(100); 
       }) 
       .DataSource(dataSource => dataSource.Custom() 
         .Type("aspnetmvc-ajax") 
         .PageSize(10) 
         .ServerPaging(true) 
         .ServerSorting(true) 
         .ServerFiltering(true) 
         .Transport(transport => transport 
          .Read("ReadPages", "Page") 
         ) 
         .Schema(schema => schema 
          .Data("result.data") 
          .Total("result.total") 
          .Errors("result.errors") 
          .Model(m => m.Id(p => p.Name)) 
         ) 
      ) 
     ) 

当我做同样的使用JavaScript,它的工作原理和数据显示。

var dataSource = new kendo.data.DataSource({ 
    transport: { 
     read: { 
      url: "@Url.Action("ReadPages", "Page")", 
      type: "post", 
      dataType: "json" 
     } 
    }, 
    schema: { 
     data: "result.data", 
     total: "result.total" 
    } 
}); 

var grid = $("#pageGrid2").kendoGrid({ 
    dataSource: dataSource 
}); 

问题在哪里?谢谢!

编辑:我得到这个回应:

{ 
    "success": true, 
    "result": { 
    "data": [ 
     { 
     "id": "1", 
     "name": "Test", 
     "content": "Test obsahu", 
     "url": "test", 
     "title": "test", 
     "description": "test" 
     }, 
     { 
     "id": "7", 
     "name": "Jmeno", 
     "content": "htmlfdgsrg erg erger", 
     "url": "test2", 
     "title": "test", 
     "description": "Desc grid" 
     } 
    ], 
    "total": 2, 
    "aggregateResults": null, 
    "errors": null 
    }, 
    "error": null, 
    "unAuthorizedRequest": false 
} 
+0

什么是使用自定义的原因绑定而不是ajax绑定? – k4st0r42

+0

因为我使用包含有关身份验证的附加数据的响应的框架。 –

+0

您能向我们展示来自Page/ReadPages的http响应的示例吗? – k4st0r42

回答

1

也许属性名称不客户方和服务器端之间的匹配,试试这个:

.Model(m => 
{ 
    m.Id(p => p.Name); 
    m.Field(p => p.Name).From("name"); 
})