Sorting Not Working With Json Result Giving Encoded Output
Solution 1:
in ASP MVC 4 you can do next IQueryable Support
Next cool feature is IQueryable support. If you need to, instead of returning "plain" IEnumerable objects from the API action, you might return IQueryable. Why?
Remember the times we implemented paging & sorting with ASP.NET MVC application. It was possible of cause, but it required a lot of manual job. Actions had to be extended with additional parameters, code have to respect those parameters and return exact portion of data we require to. The same story with sorting. In Web API it much simpler.
Change the signature and return type to IQueryable.
public IQueryable<Product> Get()
{
return _storage.AsQueryable();
}
Now, if Web API sees the method like that, it will allow to access with with Open Data Protocol (OData) query string parameters. OData provides support for following queries: $filter, $orderby, $skip, $top.
Now, if I do the request:
**http://localhost:5589/api/products?$top=3**
I will receive, 3 top products. Or something like,
**http://localhost:5589/api/products?$skip=2&$top=3**
I will skip 2 and take rest 3. In short, having IQueryable and 4 OData query parameters it's much more easy to do the stuff required more time before.
Solution 2:
Take a look at this:
Post a Comment for "Sorting Not Working With Json Result Giving Encoded Output"