Paging in Asp.net MVC example

In asp.net mvc application we can implement paging using bootstrap framework, Let's see how to implement paging in asp.net mvc application.

Asp.net MVC Pagination Example:

Paging is commonly used functionality in any web application, So let’s implement Paging in asp.net MVC

Right click on References => Manage NuGet Packages
Search for "PagedList"
Install PagedList.MVC as shown below

Paging in Asp.net MVC

Required namespace
@using PagedList 
@using PagedList.Mvc; 

Implement Paging in Asp.net MVC

Step 1: In Controller Action fetch your data from database, and assign to your IPagedList property in Model

int MaxResultPerPage=50; public ActionResult Index(int page = 1)
{
BusinessModel model = new BusinessModel();
string parameter1 = Request.QueryString["parameter1"];
IPagedList<customObject> requirements = null;
using (ServiceDTO rdto = new ServiceDTO())
{
requirements = rdto.SearchResults(skill, location,true)
.Where(r => r.Location.Contains(parameter1))
        .ToPagedList<customObject>(page, MaxResultPerPage);
        model.ActiveJobs = requirements;
               
    }
return View(model);
}

Step 2: In razor file add the reference of “bootstrappagging.css”, and take the IPagedList property in a variable

<link href="~/css/bootstrappagging.css" rel="stylesheet" />
IPagedList<customObject> objList = Model.ActiveJobs;

Step 3: loop through the collection object and display as per your need

@foreach (customObject j in objList)
{            
    // display record as per need
         
}

Step 4: Now let’s implement the pagination part

<div style="padding: 4px;">
@Html.PagedListPager(jobs, page => Url.Action("index", new { page }), PagedListRenderOptions.ClassicPlusFirstAndLast)
</div>

You should also check Bootstrap pagination example

Enjoy Paging in Asp.net MVC

 
Pagination in Asp.net MVC
Aspnet MVC Training
Asp.net MVC tutorials, learn model view controllers with c#, develop database driven web application using Asp.net MVC framework.
Hire .Net Developer
Free Tutorials
ASP.NET MVC Interview Questions Answers
Asp.Net MVC C# Examples | Join Asp.Net MVC Course | Asp.net Core Tutorial