我有一个 webapi 方法,我想打开 oData 分页等。我按照http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options中的示例进行操作
我的方法如下所示:
public PageResult<UserViewModel> GetUsers(ODataQueryOptions<UserViewModel> options)
{
var settings = new ODataQuerySettings()
{
PageSize = 2
};
var results = UserLogic.GetUsers(userId, UserManager, _db);
var filtered = options.ApplyTo(results, settings);
var pagedResult = new PageResult<UserViewModel>(
filtered as IEnumerable<UserViewModel>,
Request.GetNextPageLink(),
Request.GetInlineCount());
return pagedResult;
}
Run Code Online (Sandbox Code Playgroud)
计数已填充,下一页链接在那里,并且应用了正确的 oData 选项,即排序顺序等。当我在 api 方法中返回它时,会返回正确的数据,但计数和下一页链接不会出现在我的 json.
我是否缺少打开此功能的设置?
即这是我的 json 响应:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-RequestID: b215962b-6a4a-431d-9850-7ecbf808538e
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcUmVwb3NpdG9yaWVzXEdpdEh1YlxxbGRyYS1wb3J0YWxccWxkcmEtcG9ydGFsLldlYlxxbGRyYS5iYXNlbGluZS5hcGlcYXBpXHVzZXJz?=
X-Powered-By: ASP.NET
Date: …Run Code Online (Sandbox Code Playgroud)