Implement PagedList in VB.NET MVC3 or MVC4

How to use Paging using the PagedList

Once you have installed the PagedList package from NUGET




Add the following two imports at the top of the header

Imports PagedList
Imports PagedList.Mvc



Your Linq or SQL query should be sorted


Dim v = (From vid In db.qry_Videos Where vid.CatID = CatID Order By vid.OrderByID Select vid)

ViewBag.CurrentSort = v   ‘ This is most important you need to tell the view what your current sort order is

Return View(v)




In your view add the following imports at the top of the view

@imports PagedList
@imports PagedList.Mvc


Add the style sheet in your view as well. This will help you render your pager properly

<link href=”~/Content/PagedList.css” rel=”stylesheet” />


Wherever you want your pager to appear use the following

index” is the name of your view, if your view is named different then change it to your view

page”  – this is the variable which stores the current page number

“ – this is the ViewBag which you used in your controller

OnlyShowFivePagesAtATime  – this tells the pager how many buttons will be shown at one time ( this option shows

@Html.PagedListPager(DirectCast(ViewBag.CurrentSort, IPagedList), Function(page) Url.Action(“index“, New With {.page = page, .criteria =}), PagedListRenderOptions.OnlyShowFivePagesAtATime)