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

ASP.NET MVC 4 New Web API and oData

8 Answers 620 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave Whiting
Top achievements
Rank 1
Dave Whiting asked on 21 Feb 2012, 03:39 PM
Hi,

With the recent release of ASP.NET Web API I was hoping that KendoUI would be a a perfect match and allow the wiring up of the Kendo grid to the new APIControllers. 

I can see the correct oData API calls being made by the Grid and the .NET Web API controller responds with the correct number of json records and the correct page but this is never rendered in the grid. Do you know if the new ASP.NET Web API oData responses work?

Hope you can help or show an example of this working because if it does its going be a really elegant and simple implementation.

Example can be seen here : http://www.asp.net/web-api/overview/web-api-routing-and-actions/video-paging-and-querying 


Thanks
Mark

8 Answers, 1 is accepted

Sort by
0
Dave Whiting
Top achievements
Rank 1
answered on 22 Feb 2012, 12:21 AM
Having researched this further it would appear that the ASP.NET Web API provides the ability for basic oData Query Syntax ($top, $skip etc.) to be used against the API but it only returns JSON and no additional oData information.

I'll use a standard JSON datasource and manage the paging queries within the API myself.

Thanks
Mark
0
John
Top achievements
Rank 1
answered on 29 Feb 2012, 02:06 PM
Does Kendo UI work with asp.net web api with OData?  I cant get it to render any results..  Anyone have success with these two?
0
Jean-Pascal van der Endt
Top achievements
Rank 1
answered on 06 Mar 2012, 05:10 PM
I'd be interested to see an example of this as well. More precisely: consuming an ASP.NET Web API in a grid, asking the server to provide paged results. I'm guessing the latter should be done using oData query parameters, as Mark said previously.

The Kendo UI Datasource documentation seems rather concise about these things. I hope that plenty of examples will become available soon. Thanks guys.

EDIT: Just to clarify some more. Obviously a standard ASP.NET Web API can respond to oData parameters, but typically the results will be returned as straightforward JSON. Of course, the grid needs something else to enable paging, and it expects this format:

jQuery17108768166687720499_1331051022528(
{
    "d" :
    {
        "results" : [ { array with my objects here} ],
        "__count" : "830"
     }
})

Has anyone succeeded in getting an ASP.NET Web API to return these results?
0
Vesselin Obreshkov
Top achievements
Rank 2
answered on 06 Mar 2012, 11:01 PM
The Kendo DataSource doesn't seem to work with the Web API that ships with MVC 4 out of the box. I too started playing around with the new bits recently and was just coming here to look for a solution to the exact same problem - no data showing in my grid (even though I can see the correct data coming in using the Chrome Dev tools).

If you change the dataSource type to 'json' it will show you the results but obviously nothing else will work.

Hope we see an update soon that fixes this and makes the DataSource work with the new Web API out of the box.
0
Atanas Korchev
Telerik team
answered on 07 Mar 2012, 10:24 AM
Hi,

Please my reply in this thread.

Kind regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jesse
Top achievements
Rank 2
answered on 29 Jun 2012, 08:08 PM
Not sure if this has been solved yet. I've had success linking up the autocomplete and ListView with web api. Initially I as well couldn't get any results. In order to get it working I was required to create a Jsonp media Type formatter and change the dataType to jsonp. The paging is working in the ListView control, but I can not speak for the grid as I have not tried that yet.

So my autocomplete looks like so

  $('#autocompleteSearchInput').kendoAutoComplete({
                minLength:1,
                dataTextField:dataText,
                dataSource:new kendo.data.DataSource({
                    pageSize:100,
                    transport:{
                        read:{
                            url:"http://localhost:8181/api/values
                            dataType:"jsonp"
                        }
                    }
                })
            });

The implementation for the jsonp media type formatter can be found here. I found the last post to be the easiest to implement
http://stackoverflow.com/questions/9421312/jsonp-with-asp-net-web-api 

0
Oscar
Top achievements
Rank 1
answered on 06 Aug 2012, 02:53 AM
Hello

I spent 3 days trying to bind the amazing KendoUI MVC wrapper to WebAPI Controllers.  after many hours of Chrome dev tools exterminating the data calls  I never got the grid to show data.  then i found this great tutorial
http://www.kendoui.com/blogs/teamblog/posts/12-07-26/hello_kendo_ui_part_2_ndash_grid_crud.aspx

Unfortunately after using the techniques presented on the tutorial,  I was still not able to get data into the KendoUI Grid (with the wrapper).

Is good to know that I am not the only one having issues with this feature.

Regards
0
Burke
Top achievements
Rank 1
answered on 20 Nov 2012, 09:42 PM
Oscar

I am going to be covering this shortly.  In the meantime, please check this code sample here for a grid bound to WebAPI using the MVC Wrappers.

http://www.kendoui.com/code-library/mvc/grid/binding-to-a-web-apicontroller.aspx
Tags
Grid
Asked by
Dave Whiting
Top achievements
Rank 1
Answers by
Dave Whiting
Top achievements
Rank 1
John
Top achievements
Rank 1
Jean-Pascal van der Endt
Top achievements
Rank 1
Vesselin Obreshkov
Top achievements
Rank 2
Atanas Korchev
Telerik team
Jesse
Top achievements
Rank 2
Oscar
Top achievements
Rank 1
Burke
Top achievements
Rank 1
Share this question
or