Paging in MVC example

How to implement paging in mvc application MVC Pagination Example

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

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

Paging in MVC

Required namespace
@using PagedList 
@using PagedList.Mvc; 

Implement Paging in 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)

You should also check Bootstrap pagination example

Enjoy Paging in MVC

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