Canducci.Pagination 3.2.0

dotnet add package Canducci.Pagination --version 3.2.0
                    
NuGet\Install-Package Canducci.Pagination -Version 3.2.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="Canducci.Pagination" Version="3.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Canducci.Pagination" Version="3.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Canducci.Pagination" />
                    
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 Canducci.Pagination --version 3.2.0
                    
#r "nuget: Canducci.Pagination, 3.2.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 Canducci.Pagination@3.2.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=Canducci.Pagination&version=3.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Canducci.Pagination&version=3.2.0
                    
Install as a Cake Tool

Canducci Paginated

Note: based on repository https://github.com/TroyGoode/PagedList

Canducci Paginated

Version NuGet

Canducci Paginated Mvc

Version NuGet

Build Test

Build Status Github Workflows

Installation

  • Canducci.Pagination
PM> Install-Package Canducci.Pagination
  • Canducci.Pagination.Mvc
PM> Install-Package Canducci.Pagination.Mvc

Note: Installing the package Canducci.Pagination.Mvc already integrates the package Canducci.Pagination.

How to use

Examples

  • IQueryable
Entity Framework
static void TestIQueryablePaginated(int current, int total = 5)
{
	using (DatabaseContext db = new DatabaseContext())
	{
		Paginated<People> listOfQueryable0 = 
			db.People
				.OrderBy(x => x.Name)
				.ToPaginated(current, total);
	}
}
  • IEnumerable
StaticPaginated
public class People
{
	public int Id { get; set; }
	public string Name { get; set; }
}

public class PeopleList: List<People>
{
	public PeopleList()
	{
		Add(new People { Id = 1, Name = "Test 1" });
		Add(new People { Id = 2, Name = "Test 2" });
		Add(new People { Id = 3, Name = "Test 3" });
		Add(new People { Id = 4, Name = "Test 4" });
		Add(new People { Id = 5, Name = "Test 5" });
		Add(new People { Id = 6, Name = "Test 6" });
		Add(new People { Id = 7, Name = "Test 7" });
		Add(new People { Id = 8, Name = "Test 8" });
		Add(new People { Id = 9, Name = "Test 9" });
		Add(new People { Id = 10, Name = "Test 10" });
	}
}
static void TestIEnumerableStaticPaginated(int current, int total = 5)
{
	PeopleList listOfAllPeople = new PeopleList();
	int countOfPeople = listOfAllPeople.Count;

	IEnumerable<People> listOfPeople0 = listOfAllPeople
		.OrderBy(x => x.Id)
		.Skip((current - 1) * total)
		.Take(total)
		.ToArray();

	StaticPaginated<People> paginated0 = 
		new StaticPaginated<People>(
			listOfPeople0, 
			current, 
			total, 
			countOfPeople); 
}

Mvc - Entity Framework with HtmlHelpers e TagHelpers

  • Controller
using Canducci.Pagination;

public class HomeController : Controller
{
	public DatabaseContext Database { get; }

	public HomeController(DatabaseContext database)
	{
		Database = database;
	}

	public IActionResult Index(int? current)
	{
		var result = Database.People.OrderBy(x => x.Id).ToPaginated(current ?? 1, 3);
		return View(result);
	}
}
  • View - Configuration (_ViewImports.cshtml)

Open the file _ViewImports.cshtml and add this line @addTagHelper *, Canducci.Pagination.Mvc and in the same file add @using Canducci.Pagination.Mvc, resume:

@using Canducci.Pagination.Mvc
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Canducci.Pagination.Mvc
  • View - Index.cshtml
@model Canducci.Pagination.Paginated<People>
@{ ViewData["Title"] = "Home Page"; }


@foreach (var item in Model)
{
    <div>@item.Id - @item.Name</div>
}
<div>
    @Html.Pagination(
                    Model, 
                    current => Url.Action("Index", new { current }), 
                    PaginatedStyle.PreviousNext, 
                    new PaginatedOptions { 
                                          NextLabel = "Next", 
                                          PreviousLabel = "Previous", 
                                          FirstLabel = "First", 
                                          LastLabel = "Last" 
                                         }
    )
</div>
<div>
    @Html.Pagination(
                    Model, 
                    current => Url.Action("Index", new { current }), 
                    PaginatedStyle.FirstPreviousNextLast, 
                    new PaginatedOptions { 
                                          NextLabel = "Next", 
                                          PreviousLabel = "Previous", 
                                          FirstLabel = "First", 
                                          LastLabel = "Last" 
                                          }
    )
</div>
<div>
    @Html.Pagination(
                    Model, 
                    current => Url.Action("Index", new { current }), 
                    PaginatedStyle.Numbers, 
                    new PaginatedOptions { 
                                          NextLabel = "Next", 
                                          PreviousLabel = "Previous", 
                                          FirstLabel = "First", 
                                          LastLabel = "Last" 
                                         }
     )
</div>
<div>
    @Html.Pagination(
                    Model, 
                    current => Url.Action("Index", new { current}), 
                    PaginatedStyle.NumbersWithPreviousNext, 
                    new PaginatedOptions { 
                                          NextLabel = "Next", 
                                          PreviousLabel = "Previous", 
                                          FirstLabel = "First", 
                                          LastLabel = "Last" 
                                         }
    )
</div>
<div>
    @Html.Pagination(
                    Model, 
                    current => Url.Action("Index", new { current }),
                    PaginatedStyle.NumbersWithFirstPreviousNextLast, 
                    new PaginatedOptions { 
                                          NextLabel = "Next", 
                                          PreviousLabel = "Previous", 
                                          FirstLabel = "First", 
                                          LastLabel = "Last" 
                                         }
    )
</div>

<h3>TagHelper</h3>

<div>
    <pagination pagination-asp-action="Index"
                pagination-asp-controller="Home"
                pagination-style="PreviousNext"
                pagination-css-class-ul="pagination"
                pagination-paginated="Model"
                pagination-label-next="Next"
                pagination-label-previous="Previous"
                pagination-css-class-anchor="page-link"
                pagination-css-class-li="page-item"
                pagination-css-class-li-disabled="disabled">
    </pagination>
</div>
<div>
    <pagination pagination-asp-action="Index"
                pagination-asp-controller="Home"
                pagination-style="FirstPreviousNextLast"
                pagination-css-class-ul="pagination"
                pagination-paginated="Model"
                pagination-label-next="Next"
                pagination-label-previous="Previous"
                pagination-label-first="First"
                pagination-label-last="Last"
                pagination-css-class-anchor="page-link"
                pagination-css-class-li="page-item"
                pagination-css-class-li-disabled="disabled">
    </pagination>
</div>

<div>
    <pagination pagination-asp-action="Index"
                pagination-asp-controller="Home"
                pagination-style="Numbers"
                pagination-css-class-li-active="active"
                pagination-css-class-ul="pagination"
                pagination-paginated="Model"
                pagination-label-next="Next"
                pagination-label-previous="Previous"
                pagination-label-first="First"
                pagination-label-last="Last"
                pagination-css-class-anchor="page-link"
                pagination-css-class-li="page-item"
                pagination-css-class-li-disabled="disabled">
    </pagination>
</div>

<div>
    <pagination pagination-asp-action="Index"
                pagination-asp-controller="Home"
                pagination-style="NumbersWithPreviousNext"
                pagination-css-class-li-active="active"
                pagination-css-class-ul="pagination"
                pagination-paginated="Model"
                pagination-label-next="Next"
                pagination-label-previous="Previous"
                pagination-label-first="First"
                pagination-label-last="Last"
                pagination-css-class-anchor="page-link"
                pagination-css-class-li="page-item"
                pagination-css-class-li-disabled="disabled">
    </pagination>
</div>

<div>
    <pagination pagination-asp-action="Index"
                pagination-asp-controller="Home"
                pagination-style="NumbersWithFirstPreviousNextLast"
                pagination-css-class-li-active="active"
                pagination-css-class-ul="pagination"
                pagination-paginated="Model"
                pagination-label-next="Next"
                pagination-label-previous="Previous"
                pagination-label-first="First"
                pagination-label-last="Last"
                pagination-css-class-anchor="page-link"
                pagination-css-class-li="page-item"
                pagination-css-class-li-disabled="disabled">
    </pagination>
</div>

<div>
    <pagination pagination-asp-action="Index"
                pagination-asp-controller="Home"
                pagination-style="NumbersWithFirstPreviousNextLast"                
                pagination-paginated="Model"
                pagination-label-next="Next"
                pagination-label-previous="Previous">
    </pagination>
</div>

Razor Pages

  • PageModel Peoples
using System.Linq;
using Canducci.Pagination;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Canducci.WebAppRazorPages.Test.Pages
{
    public class PeoplesModel : PageModel
    {
        private readonly DatabaseContext Context;
        public PeoplesModel(DatabaseContext context)
        {
            Context = context;            
        }

        public Paginated<People> Items { get; private set; }
        
        public void OnGet(int? current)
        {            
            Items = Context.People
                .OrderBy(x => x.Name)
                  .ThenBy(x => x.Id)
                .ToPaginated(current ?? 1, 4);
        }
    }
}
  • View Peoples
@page "page-{current=1}"
@model PeoplesModel
<br />
<table class="table table-striped">
    <thead>
        <tr>
            <th style="width:5%">Id</th>
            <th style="width:95%">Name</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.Items)
        {
        <tr>
            <td>@item.Id</td>
            <td>@item.Name</td>
        </tr>
        }
    </tbody>
    <tfoot>
        <tr>
            <td colspan="2" class="text-center">
                <pagination pagination-asp-page="Peoples"
                            pagination-asp-page-handler="page-{current=1}"
                            pagination-style="NumbersWithFirstPreviousNextLast"
                            pagination-css-class-li-active="active"
                            pagination-css-class-ul="pagination"
                            pagination-paginated="Model.Items"
                            pagination-label-next="Next"
                            pagination-label-previous="Previous"
                            pagination-label-first="First"
                            pagination-label-last="Last"
                            pagination-css-class-anchor="page-link"
                            pagination-css-class-li="page-item"
                            pagination-css-class-li-disabled="disabled">
                </pagination>
            </td>            
        </tr>
        <tr>
            <td colspan="2" class="text-center">
                @Html.Pagination(
                                 Model.Items, 
                                 current => Url.Page("Peoples", new { current }), 
                                 PaginatedStyle.NumbersWithFirstPreviousNextLast, 
                                 new PaginatedOptions { 
                                                      NextLabel = "Next", 
                                                      PreviousLabel = "Previous", 
                                                      FirstLabel = "First", 
                                                      LastLabel = "Last" 
                                                      }
                )
            </td>
        </tr>
    </tfoot>
</table>

Example Pagination

Pagination-Example

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Canducci.Pagination:

Package Downloads
Canducci.Pagination.Mvc

Pagination Razor Pages and Traditional Mvc

ENT.Framework

Contact for support: eduardo@entechnology.com.br

FwLux.Backend

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0 469 12/14/2025
3.1.0 17,744 10/21/2024
3.0.0 39,075 1/15/2023
2.1.2 43,687 12/31/2020
2.1.1 1,669 8/20/2020
2.1.0 1,317 8/19/2020
2.0.0 1,313 12/22/2019
1.0.3.1 2,546 4/16/2018
1.0.3 2,156 4/13/2018
1.0.2 2,476 4/11/2018
1.0.1 1,867 4/11/2018
1.0.0 1,843 4/10/2018