Reputation: 1879
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
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