Skip to content

Instantly share code, notes, and snippets.

@mikebrind
Created October 9, 2018 07:40
Show Gist options
  • Save mikebrind/cf8f3c8a2684595918816461d4fb8dea to your computer and use it in GitHub Desktop.
Save mikebrind/cf8f3c8a2684595918816461d4fb8dea to your computer and use it in GitHub Desktop.
public class PaginationModel : PageModel
{
private readonly IPersonService _personService;
public PaginationModel(IPersonService personService)
{
_personService = personService;
}
[BindProperty(SupportsGet = true)]
public int CurrentPage { get; set; }
[BindProperty(SupportsGet = true)]
public string SortBy { get; set; }
public int Count { get; set; }
public int PageSize { get; set; } = 10;
public int TotalPages => (int)Math.Ceiling(decimal.Divide(Count, PageSize));
public List<Models.Person> Data { get; set; }
public bool ShowPrevious => CurrentPage > 1;
public bool ShowNext => CurrentPage < TotalPages;
public bool ShowFirst => CurrentPage != 1;
public bool ShowLast => CurrentPage != TotalPages;
public async Task OnGetAsync()
{
Data = await _personService.GetPaginatedResult(CurrentPage, PageSize, SortBy);
Count = await _personService.GetCount();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment