我正在尝试使用 ASP 5.0 WebAPI 在客户 Controller 中进行分页。当我尝试做这个例子时,我得到:
Cannot implicitly convert type Microsoft.AspNet.Mvc.HttpOkObjectResult to API.Controllers.IHttpActionResult
我只需要返回一个包含当前页数、总页数和结果的客户集合。
public IHttpActionResult Get(int offset = 0, int limit = 50)
{
// Get total number of records
int total = _dbContext.Customers.Count();
// Select the customers based on paging parameters
var customers = _dbContext.Customers
.OrderBy(c => c.Id)
.Skip(offset)
.Take(limit)
.ToList();
// Return the list of customers
return Ok(new
{
Data = customers,
Paging = new
{
Total = total,
Limit = limit,
Offset = offset,
Returned = customers.Count
}
});
}
最佳答案
您需要将IHttpActionResult
更改为IActionResult
Controller.Ok()
返回 HttpOkObjectResult ...
public class HttpOkObjectResult : ObjectResult, IActionResult {...}
...而您的方法签名定义了 IHttpActionResult
,它来自以前的版本
关于c# - WebAPI One Asp.Net (ASP5/vNext) 中的分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36961976/