AspNetCore.PaginatedList 8.0.0

dotnet add package AspNetCore.PaginatedList --version 8.0.0
                    
NuGet\Install-Package AspNetCore.PaginatedList -Version 8.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspNetCore.PaginatedList" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspNetCore.PaginatedList" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AspNetCore.PaginatedList" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AspNetCore.PaginatedList --version 8.0.0
                    
#r "nuget: AspNetCore.PaginatedList, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AspNetCore.PaginatedList@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AspNetCore.PaginatedList&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AspNetCore.PaginatedList&version=8.0.0
                    
Install as a Cake Tool

AspNetCore.PaginatedList

Classe utilitaire générique permettant de paginer une liste d'éléments en .NET / ASP.NET Core.

Fonctionnalités

  • Pagination d'une liste générique List<T>
  • Calcul automatique du nombre total de pages
  • Indication de l'existence d'une page précédente
  • Indication de l'existence d'une page suivante
  • Retour d'un objet contenant les métadonnées de pagination

Installation

Ajoutez la classe PaginatedList<T> dans votre projet :

namespace AspNetCore.PaginatedList;

Utilisation

var users = new List<User>
{
    new User { Id = 1, Name = "Majdi" },
    new User { Id = 2, Name = "Sara" },
    new User { Id = 3, Name = "Ali" }
};

int pageIndex = 1;
int pageSize = 10;

var result = PaginatedList<User>.Create(users, pageIndex, pageSize);

Réponse retournée

{
  "Data": [],
  "HasNextPage": false,
  "HasPreviousPage": false,
  "TotalPages": 1,
  "PageIndex": 1,
  "PageSize": 10,
  "TotalCount": 3
}

Propriétés

Propriété Description


Data Liste des données HasNextPage Indique s'il existe une page suivante HasPreviousPage Indique s'il existe une page précédente TotalPages Nombre total de pages PageIndex Page actuelle PageSize Nombre d'éléments par page TotalCount Nombre total d'éléments

Exemple avec un contrôleur ASP.NET Core

[HttpGet]
public IActionResult GetUsers(int pageIndex = 1, int pageSize = 10)
{
    var users = _context.Users.ToList();

    var result = PaginatedList<User>.Create(users, pageIndex, pageSize);

    return Ok(result);
}

Remarque

Dans l'implémentation actuelle, la propriété Data retourne source.ToList().

Pour retourner uniquement les éléments paginés, remplacez :

Data = source.ToList()

par :

Data = items

Licence

Projet libre d'utilisation.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.0 106 5/5/2026
6.0.0 2,900 10/15/2019
5.0.0 761 10/15/2019
4.0.0 734 10/15/2019
3.0.0 878 6/17/2019
2.0.0 759 6/17/2019
1.0.0 773 6/17/2019