Click here to Skip to main content
14,869,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am using PagedList in a fully functional pager and it is generating the query string for the indexed pages as expected. 

I wanted to know if there is a way the URL could be customized to eliminate the query string and add another Route parameter instead.
 
The following is my View :- 
   <pre>
    @model PagedList.Core.IPagedList<ActionAugerMVC.Models.Review>
    @using PagedList.Core.Mvc;
    @addTagHelper *, PagedList.Core.Mvc

    <div id='Paging' style="text-align:center">
         Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
         <pager class="pager-container" list="@Model" 
                options="@PagedListRenderOptions.TwitterBootstrapPager" 
                asp-action="Index" asp-controller="Review" />
    </div> 

And here is my Controller Action :-

[Route("Reviews/calgary-tech-reviews")]
public IActionResult Index(int? page)
{
    int pageSize = 10;
    int pageIndex = 1;
    pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;

    var review = unitOfWork.ReviewRepository.GetAll();
    return View(review.OrderByDescending(m=> m.Date).ToPagedList(pageIndex,pageSize));
}

The current URL looks like this :-
http://localhost:63613/Reviews/calgary-tech-reviews?page=2

And I want it to look like this :-
http://localhost:63613/Reviews/calgary-tech-reviews/page-2/

OR
http://localhost:63613/Reviews/page-2/calgary-tech-reviews/

Any assistance would be appreciated, as I am still new this !
Thanks once again !

What I have tried:

I have tried to look into the implementation and documentation of PagedList to see how I can override it. I did discover that all the pages were being generated as tags with the quyerystring appended to it, so I was trying to figure out a way to undo that.
Posted
Updated 14-Apr-18 6:05am

1 solution

it may help :
[Route("Reviews/calgary-tech-reviews/page={page:int}")]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900