This is a migrated thread and some comments may be shown as answers.

Issue binding/dispalying data in grid (using razor vs. javascript)

1 Answer 28 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 29 Nov 2013, 04:17 PM
I have a grid that  I am displaying and I am trying 2 different methods....  The jquery version works and displays the data in the grid...

In Fiddler, I can see the return JSON and everything looks as it should in the browser 

 var url = "/memo/a/8/b/1";  // build URL to API

            var dataSource = new kendo.data.DataSource({    // create datasource
                transport: {
                    read: {
                        url: url,
                        dataType: "json",
                    }
                }
            });

When I try the same call using Razor (my preferred way), this will not display any data in the grid.   I see in Fiddler the exact same return JSON as as the Jquery method above.  But no data is being displayed.   Any suggestions?

@(Html.Kendo().Grid<eWJB.Models.MemoModel>()
    .Name("grid1")
    .Columns(columns =>
        {
            columns.Bound(p => p.MemoID);
            columns.Bound(p => p.Subject).Width(100).Title("Subject");
            columns.Bound(p => p.Initials).Width(30).Title("Initials");

    })
    .DataSource(dataSource => dataSource
        .Ajax()
       .Read(read => read.Url(Url.RouteUrl("GetAllMemos",  new {httproute ="", controller="Memo", branch=1, id=8 })).Type(HttpVerbs.Get))
         )
    .Sortable()
    .Scrollable()
    
)

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 03 Dec 2013, 10:08 AM
Hi Bob,

Basically the Grid wrapper expects differently formatted "json" (the data should be nested inside "Data" field from the response) - that why I would suggest to use the "ToDataSourceResult" extension method to format the data correctly. For more information you can check the following help article:

 
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or