Skip to content

HasPreviousPage returns true for out-of-range page numbers #1392

@ArefAbdoli

Description

@ArefAbdoli

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:

  1. Use PaginatedList.CreateAsync with any data source that results in TotalPages = 100.
  2. Pass pageNumber = 102 as a parameter.
  3. Check the value of HasPreviousPage.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions