0

I have tried to create a paging with list. i tried below code

IList<portable.ActionReturnResult> GetPage(
    IList<portable.ActionReturnResult> list, int page, int pageSize)
{
    return list.Skip(page * pageSize).Take(pageSize).ToList();
}

IList<portable.ActionReturnResult>  Pageload = 
    GetPage(appBase.Results, currentpage, pageSize).ToList();

This code not return correct value. I have 100 records(page size is 5 and 20 pages) if my page=20 and page size=5 then this return 0. is this code correct? i found this.

I tried this sample

I need load my 20 th page load(with last 5 records)

DavidG
  • 113,891
  • 12
  • 217
  • 223
A M N Kumari
  • 79
  • 2
  • 7

1 Answers1

1

In your code, pages start at zero, so page 20 would require 105 records. If you want your page number to start at 1, you need to make a minor change to your code:

IList<portable.ActionReturnResult> GetPage(IList<portable.ActionReturnResult> list, 
    int page, int pageSize)
{
    return list.Skip((page-1) * pageSize).Take(pageSize).ToList();
                    //subtract 1 here
}
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • Thanks DavidG. it works. another one to know my list is not refreshing when i change page – A M N Kumari Feb 27 '19 at 10:10
  • That's a different question completely, one we can't even begin to guess as we don't have the rest of the code. This question is now complete and you should consider marking it as accepted. – DavidG Feb 27 '19 at 10:12