implementing oData inlinecount using asp.net webapi [duplicate]

依然范特西╮ 提交于 2019-12-04 19:06:58

I had the exact issue last week. Check out Extending your ASP.NET Web API responses with useful metadata

I used this post and sample code to get a paging grid up and running using OData. As detailed in the sample I created a delegating handler to capture the HttpResponseMessage and wrap it in custom metadata that includes an item count. A custom attribute, CustomQueryableAttribute, is also created that inherits the default QueryableAttribute.

It may sound a little complex here but is actually pretty simple to implement. I had something up and running in about 30 minutes.

Hopefully future versions of the Web API have more complete OData support.

EDIT: Odata support will NOT be shipping with the Web API. The queryable attribute is being removed for the RTM release. More complete OData support will be available sometime after the initial relase via a separate Nuget package.

The SPA DataController (which is derived from the ApiController) used to implement this functionality. However, with the latest changes, it has been removed, as they plan to support OData in a different manner.

If you're working with the MVC 4 Beta, then you can simply change your controller to a DataController, and you're set. If you're using the RC, then you should take a look at an older ASP.NET Webstack commit on Codeplex. The method you're interested in is ExecuteAsync, from DataController.cs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!