DataSource not working with ASP.NET Web API oData

9 posts, 0 answers
  1. Vesselin Obreshkov
    Vesselin Obreshkov avatar
    81 posts
    Member since:
    Jan 2010

    Posted 06 Mar 2012 Link to this post

    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
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 07 Mar 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Vesselin Obreshkov
    Vesselin Obreshkov avatar
    81 posts
    Member since:
    Jan 2010

    Posted 07 Mar 2012 Link to this post

    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.

  5. Brandon
    Brandon avatar
    3 posts
    Member since:
    Nov 2011

    Posted 07 Mar 2012 Link to this post

    Just wanted to say I'm definitely looking forward to when this all works seamlessly together!
  6. Ryan
    Ryan avatar
    5 posts
    Member since:
    Sep 2010

    Posted 09 Mar 2012 Link to this post

    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.
  7. Jack
    Jack avatar
    100 posts
    Member since:
    Jan 2007

    Posted 09 Mar 2012 Link to this post

    'webapi' is definitely a must have for our company too.
  8. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 09 Mar 2012 Link to this post

    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!
  9. Brian Vallelunga
    Brian Vallelunga avatar
    88 posts
    Member since:
    May 2008

    Posted 21 Mar 2012 Link to this post

    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".
  10. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 22 Mar 2012 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready