Press "Enter" to skip to content

How to do Pagination in ASP.Net MVC ?

Md Saud 0

Sharing is caring !!

Performing paging here by adding the NuGet Package named PagedList.Mvc.

One Way 

1)   add namespace  PagedList.Mvc
In Controller
using PagedList;
 2) in Action method

 Public ActionResult Category(,int? page,)
{
 int itemperpage=10;// item want to show in one page
int pagenumber =page??1;
var categories=Db.GetCategory();
return view(Categories.ToPagedList(pagenumber,itemperpage));  //here we using topagedlist and passing page                                                                                                                 number and item in one page
}

 

3) in view we need to add
@model PagedList.IPagedList<abc.model.VWasd>
@using PagedList.MVC;
and
<div class=”pagination-bar”>
<ul class=”pagination”>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action(“Categories”, “Home”, new { page }))
</ul>
</div>

   Second Way

a) we are creating one class Pager.cs  in modle layer
b.add   PagedList.Mvc
In Controller
using PagedList;
in action method
public ActionResult Index( , int? page)
{
     return View(viewModel);
 }
In View
@model IMA.Model.ThreadModel
   where to show Pagination —>
  and  it will show like this

Sharing is caring !!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

shares