C# MVC 5 Razor PagedList: Selecting and displaying a specific page

In a MVC structure using Razor and C#, I am using Mvc.PagedList in order to display pagination for my lists:

enter image description here

Now, this works fine; but as you can see, in my case, I can have a lot of pages to display. The client has asked me to give him an option in order to jump to a specific page. I have seen some websites where this is done through the use of the "..." button; but here, it does nothing.

My questions, therefore, are:

  1. Is there any way to do this natively with Mvc.PagedList?
  2. If there isn't, what's my best option to answer the client's demand? Do I just create a DropDownList that contains all available page numbers, then it jumps to that page? Do I let him enter the page number?

Sample code for the PagedListPager:

@Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { page, currentFilter = ViewBag.CurrentFilter }), new PagedListRenderOptions { LiElementClasses = new[] { "needsLoading" } })

Thank you in advance for any and all help you can give me.

Upvotes: 2

Views: 1270

Answers (2)

J88
J88

Reputation: 829

Just use the page parameter with the specific page, you could create a list with all pagenumbers in your controller and then use this in a dropdownmenu , or anything you can imagine :D

Upvotes: 0

Chris Pratt
Chris Pratt

Reputation: 239300

How you implement it is entirely up to you or the client. Either way you mentioned will work; just pick one.

As for going directly to a specific page, you simply pass the page number you want with the URL for the page. Typically, that would look something like:

/my/awesome/paged/list?page=1

Where page is the name of your action parameter that holds the current page number and 1 would obviously be the page you want to go to.

Upvotes: 1

Related Questions