Search code examples
c#asp.netentity-frameworkpaginationskip-take

I am try to Pagination using Skip Take in Code Frist Approach But given Error


I am trying to Pagination using Skip Take in Code First Approach But given Error. enter image description here

Method

 [HttpPost]
    [Route("Paging")]

    public async ActionResult<IEnumerable<City>> Paging(int CurrentPage)
    {
        CurrentPage = CurrentPage;
        return   _dropdowncontext.cities.OrderBy(x=>x.CityId).Skip((CurrentPage - 1) * 5).Take(5);
    }

Solution

  • [HttpPost]
    [Route("Paging")]
    public async Task <ActionResult<IQueryable<City>>> Paging(int CurrentPage=1)
        {
        var abc= await _dropdowncontext.cities.OrderBy(x=>x.CityId).Skip((CurrentPage - 1) * 5).Take(5).ToListAsync();
    
            if (!abc.Any())
                return NotFound();
            return Ok(abc);
        }