Using OData Filters with C# MVC 4 Web Api and Backbone
asp.net-mvc-4, asp.net-web-api, backbone.js, c#
Solution
I experimented with a plugin from Addy Osmani called backbone.paginator. If you are working with a Web Api like MVC 4, I believe this will be a great fit. All you do is extend your collection with a handful of parameters provided by the Paginator. Eg.
perPageAttribute: '$top',
skipAttribute: '$skip',
orderAttribute: 'orderBy',
customAttribute1: '$inlinecount',
queryAttribute: '$filter',
formatAttribute: '$format',
customAttribute2: '$callback',`
Problem
This is the first time I have experimented with the awesome Web Api and Backbone. So far everything seems like a match made in heaven. However I cant seem to return the relevant data using the OData filters. For Example I have the following as an action method: ``` //GET /api/posts/ public IQueryable<KiaFamilyPost> Get() { return _db.Posts .Include("Badge") .Include("Entry") .AsQueryable(); } ``` Now I would like to filter the above posts, and return them in descending order. From my understanding I could do the following "http://[MySite]/api/posts?$filter=id eq 2&$orderby=DatePost desc". I am trying to do the following to no avail: ``` APP.posts_collection.fetch({data: { entryId: APP.entry.get('Id'), $order: 'Id desc' }}); ``` Backbone makes the following call to the controller "http://[MySite]/api/posts?entryId=1&%24order=Id+desc". Anyone been able to get this to work correctly? Thanks Tyrone