I am working on a standard paging component for my project. All controllers with paging are waiting for PageIndex parameter in URL.
So I want to generate URL based on the current URL except for the PageIndex parameter.
For example, I have filters for my internet store like Manufacturer and MaxPrice.
A user opens the mystore.com/products?manufacturer=Apple&MaxPrice=999 link.
Then he wants to go to the 3 pages. So the 3-page link in my paging should have the mystore.com/products?manufacturer=Apple&MaxPrice=999&PageIndex=3 link.
So needed MVC function should:
- Persists all existing params like MaxPrice and manufacturer
 - Replace only PageIndex param
 - don't use any hardcoded controller and action values (like controller = 'Products', Action = 'Index')
 
I try to use this code:
<a class="page-link" href="@Url.RouteUrl(new { PageIndex = page })">
    @page
</a>
It works fine except the 2 rule - it doesn't persist other arguments.
So if user click on this link he goes to mystore.com/products?PageIndex=3
