MVC Kendo 网格自定义数据源

MVC Kendo grid custom dat source

我为 kendo MVC 网格创建了自定义数据源。 Everythink 正在运行,数据正在从服务器返回。但在网格中只显示空单元格。就像这张图片: MVC 网格代码:

            @(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
}

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

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