How to use PagedList.MVC in MVC5 using VB.NET

Installed the PagedList.MVC  in your project using the NuGET

This is the ASP.NET Syntax

In your Controller


At the top of the Controller add the following two imports

Imports PagedList
Imports PagedList.Mvc


Here is a sample ViewResult

Function NewVideos(Optional ByVal Page As Integer = 1) As ViewResult
Dim videos = rep.GetNewVideos.ToPagedList(Page, 10)  ‘ Code to get your data  use your own

ViewBag.CurrentSort = videos
Return View(videos)

End Function


In your View

At the top of the page add the following imports

<%@ import Namespace=”PagedList” %>
<%@ import NameSPace=”PagedList.Mvc” %>


Where you want the Pager to appear add the following code. Customize it according to your need.


<%: Html.PagedListPager(DirectCast(ViewBag.CurrentSort, IPagedList), Function(page) Url.Action(“newvideo“, New With {.page = page}), PagedListRenderOptions.OnlyShowFivePagesAtATime)%>