-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Describe the bug
The HasPreviousPage property in PaginatedList currently returns true even when the requested PageNumber is outside the valid page range.
For example, if TotalPages = 100 and PageNumber = 102, HasPreviousPage still returns true, although page 101 doesn’t actually exist.
To Reproduce
Steps to reproduce the behavior:
- Use PaginatedList.CreateAsync with any data source that results in TotalPages = 100.
- Pass pageNumber = 102 as a parameter.
- Check the value of HasPreviousPage.
- The property returns true even though there is no valid previous page.
Expected behavior
HasPreviousPage should only return true when the previous page actually exists within the valid range [1, TotalPages].
Proposed fix
Replace the original condition:
public bool HasPreviousPage => PageNumber > 1;
with:
public bool HasPreviousPage => PageNumber > 1 && PageNumber <= TotalPages + 1;
Additional context
This change ensures that HasPreviousPage correctly reflects the existence of a valid previous page and prevents misleading results for out-of-range page numbers.