Question

I have an ASP.NET Web API project. I'm trying to pass some query options to my API controller like so:

http://localhost:61736/api/Enquiries?
callback=callback&$top=30&$skip=30&orderby=EnquiryId
&$inlinecount=allpages&_=1346164698393

But I get the following:

The query parameter '$inlinecount' is not supported.

I also get the same when I try to use $callback, $format

Any idea what I'm doing wrong? According to: http://msdn.microsoft.com/en-us/library/ff478141.aspx I should be able to use them?

Was it helpful?

Solution

The ASP.NET Web API provides only limited support for OData as documented in this blog post. I didn't see the query parameters you mention in that list.

OTHER TIPS

In current version, web api only supports $filter, $orderby, $top and $skip. You can override QueryableAttribute to add more support on OData protocol. A checkin after public nuget release has made ValidateQuery method virtual so that you can override it to bypass the validation. Please try our nightly build at http://www.myget.org/F/aspnetwebstacknightly/.

You can also use ODataQueryOptions. The following code is equivalent to [Queryable] attribute, except that it won't throw exception when it sees unsupported options.

public IEnumerable<Product> Get(ODataQueryOptions options) 
{
    return options.ApplyTo(_db.Products as IQueryable) as IEnumerable<Product>; 
}

You can get $inlinecount by ODataQueryOptions.RawValues.InlineCount. For detail of OData query support, please see: http://blogs.msdn.com/b/alexj/archive/2012/08/21/web-api-queryable-current-support-and-tentative-roadmap.aspx

Support for $inlinecount was checked into the project on 12/6/2012, presumably the next release will contain this support. you can download the latest source or pick up a nightly build:

http://aspnetwebstack.codeplex.com/SourceControl/changeset/ed65e90e83c8

Revision: ed65e90e83c8f9391b4f4806d305c83f55d28ff6
Author: youssefm < youssefm@microsoft.com >
Date: 12/6/2012 1:51:44 PM
Message:
[OData] Add support for the $inlinecount query option

I believe nightly packages are pushed to http://www.myget.org/F/aspnetwebstacknightly/ but I have not verified myself.

If you're using KendoUI by any chance this post explains how to disable some of the options such as $callback by switching to JSON instead of JSONP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top