0
votes

I created custom datasource for my kendo MVC grid. Everythink is working, data are comming back from server. But in grid are displayed only empty cells. Like on this image: Empty cells Code for MVC grid:

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

When I do the same with javascript, it works and data are showed.

    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
});

Where is the problem ? Thanks!

EDIT: I got this response:

    {
  "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
}
1
What is the reason of using a custom binding instead of an ajax binding ?k4st0r42
Because I use framework that wraps response with additional data about auth and etc..Martin Haščák
Could you show us an example of http response from Page/ReadPages ?k4st0r42
Ofcourse I updated my question...Martin Haščák

1 Answers

2
votes

Maybe the name of the property doesn't match between clientside and serverside, Try this :

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