Dheeraj Palagiri
Dheeraj Palagiri

Reputation: 1879

PagedList MVC Show only page numbers which are greater than current Page number

I have created pagination for an mvc project using PagedList, all ok until a new requirement came in:

Is there a way to do this? I have checked PagedListRenderOptions(), could not find a property for this.

Any suggestions will be appreciated.

Upvotes: 0

Views: 4658

Answers (1)

CiucaS
CiucaS

Reputation: 2128

I saw no one answered this, even it's almost one year old. I've got the same issue today.

In the view where you create the pages. Default the code looks like this

 @Html.PagedListPager(Model, page => Url.Action("Index",
                     new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))

Method PagedListPager has an other overload where you can put PagedListRenderOptions

So the final code should look like this if you want 3 pages to be shown.

 @Html.PagedListPager(Model, page => Url.Action("Index",
                     new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }), new PagedListRenderOptions {
                         DisplayLinkToFirstPage = PagedListDisplayMode.Never,
                         DisplayLinkToLastPage = PagedListDisplayMode.Never,
                         DisplayLinkToPreviousPage = PagedListDisplayMode.Always,
                         DisplayLinkToNextPage = PagedListDisplayMode.Always,
                         MaximumPageNumbersToDisplay = 3
                     })) 

Edit :

here is where I got my inspiration from:

https://github.com/troygoode/PagedList/blob/master/src/PagedList.Mvc/PagedListRenderOptions.cs

Upvotes: 7

Related Questions