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

DataSource not working with ASP.NET Web API oData

8 Answers 572 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Vesselin Obreshkov
Top achievements
Rank 2
Vesselin Obreshkov asked on 07 Mar 2012, 04:01 AM
After playing around with the new MVC 4 and Web API, I (like several others) noticed that the DataSource doesn't work with the data returned from using a Web API project. I'm attaching a simple solution to look at. No errors, changing the binding type to 'json' from 'odata' will show results.

We know the Web API doesn't support all oData specs but supports enough to implement paging, filtering and sorting.

* Project is written in VS11 and .NET 4.5

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 07 Mar 2012, 08:46 AM
Hello,

 The "odata" type of DataSource should be used only with full implementations of OData. Web API is not OData and returns JSON in different format than the one returned by an OData service. The Kendo DataSource expects valid OData response in order to work.
 
If you want to use the odata parameter map to translate the current filter, page and sort expressions to OData format you can check this forum thread.

Perhaps in the long term a new type of data source "webapi" would be introduced which would support the response from Web API. 

 On a side note WebAPI does not seem to currently support $inlinecount which effectively disables any paging support.

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
Vesselin Obreshkov
Top achievements
Rank 2
answered on 07 Mar 2012, 02:56 PM
Yeah I realize that. I think it's best to wait and see what they do for RTM with this. I was reading somewhere on Twitter they might be even replacing the default JSON Parser used in Web API too. Hopefully they expose more stuff to make it more usable.

Either way, this demo was modeled after this blog post by Stephen Walter:
http://stephenwalther.com/blog/archive/2012/03/05/introduction-to-the-asp-net-web-api.aspx

He mentions at the bottom using $top and $skip to implement paging. I'll play with it more when I have time. Thanks for pointing out to this paramterMap override thread. I was looking at the parameterMap last night myself but was too tired to dissect parameters last night.

Adding a 'webapi' type to the DataSource though would be a great solution if you can get basic paging, sorting and filtering working. Even if there are limitations, if the core stuff works, I think this will be great in the end. It'll make building apps with Kendo and Web API so easy and fast. Well other than trying to use it as odata source, everything else works fine when treating it as plain JSON. If we can implement paging, filtering and sorting using some generic way using parameterMap override that should work too in the short term.

0
Brandon
Top achievements
Rank 1
answered on 07 Mar 2012, 09:44 PM
Just wanted to say I'm definitely looking forward to when this all works seamlessly together!
0
Ryan
Top achievements
Rank 1
answered on 09 Mar 2012, 03:20 PM
Add me to the list of people that would like to see webapi work seamlessly with kendo.  As the author of the KendoGridBinder, I know first-hand, json is a nasty way to business as the requests are not very pleasant to deal with.
0
Jack
Top achievements
Rank 2
Iron
answered on 09 Mar 2012, 04:49 PM
'webapi' is definitely a must have for our company too.
0
Atanas Korchev
Telerik team
answered on 09 Mar 2012, 05:27 PM
Hello,

 The recommended way to proceed is to open a new user voice item for this.

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
Brian Vallelunga
Top achievements
Rank 1
answered on 21 Mar 2012, 07:17 PM
Perhaps instead of fully supporting Web API, which would be great of course, you instead allow finer control over the data source format. Specifically, instead of blanket "odata" or "json" data types, we're allowed to set query data format separately from response data format. So the query format could be "odata" while the response would be "json".
0
Atanas Korchev
Telerik team
answered on 22 Mar 2012, 09:56 AM
Hello,

 Currently the datasource has no notion of response and request formats. The only specialized kind of data source is OData.

I think what you need can be achieved even now bu using the odata parameter map:

dataSource:{
    transport: {
         read: {
             dataType: "json"
         },
         parameterMap: kendo.data.transports.odata.parameterMap
    }
}


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!
Tags
Data Source
Asked by
Vesselin Obreshkov
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Vesselin Obreshkov
Top achievements
Rank 2
Brandon
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Jack
Top achievements
Rank 2
Iron
Brian Vallelunga
Top achievements
Rank 1
Share this question
or