title: Set query parameter based on current URL
body: <p>I am working on a standard paging component for my project. All controllers with paging are waiting for PageIndex parameter in URL.</p>
  
  <p>So I want to generate URL based on the current URL except for the PageIndex parameter.</p>
  
  <p>For example, I have filters for my internet store like Manufacturer and MaxPrice.
  A user opens the <code>mystore.com/products?manufacturer=Apple&amp;MaxPrice=999</code> link.</p>
  
  <p>Then he wants to go to the 3 pages. So the 3-page link in my paging should have the <code>mystore.com/products?manufacturer=Apple&amp;MaxPrice=999&amp;PageIndex=3</code> link.</p>
  
  <p><a href="https://i.stack.imgur.com/r9Ey1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r9Ey1.jpg" alt="enter image description here"></a></p>
  
  <p>So needed MVC function should:</p>
  
  <ol>
  <li>Persists all existing params like MaxPrice and manufacturer</li>
  <li>Replace only PageIndex param</li>
  <li><strong>don't</strong> use any hardcoded controller and action values (like controller = 'Products', Action = 'Index')</li>
  </ol>
  
  <p>I try to use this code:</p>
  
  <pre><code>&lt;a class="page-link" href="@Url.RouteUrl(new { PageIndex = page })"&gt;
      @page
  &lt;/a&gt;
  </code></pre>
  
  <p>It works fine except the 2 rule - it doesn't persist other arguments.
  So if user click on this link he goes to <code>mystore.com/products?PageIndex=3</code></p>