Created
October 9, 2018 07:40
-
-
Save mikebrind/cf8f3c8a2684595918816461d4fb8dea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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