3

I'm trying to make pagination in a Customer controller using ASP 5.0 WebAPI. When I try to do this example I get:

Cannot implicitly convert type Microsoft.AspNet.Mvc.HttpOkObjectResult to API.Controllers.IHttpActionResult

I just need to return a collection of customers with the number of the current page, total of pages and results.

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 } }); } 
1
  • change IHttpActionResult to IActionResult Commented May 1, 2016 at 3:40

1 Answer 1

2

You need to change IHttpActionResult to IActionResult

Controller.Ok() returns HttpOkObjectResult...

public class HttpOkObjectResult : ObjectResult, IActionResult {...} 

...while your method signature defines IHttpActionResult, which is from the previous version

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.