title: C# ASP.NET MVC: Dynamic Querystring for Search
body: <p>I have the following scenario: </p>
  
  <p>1) A phone book table</p>
  
  <p>2) Multiple ways of searching through the table (first name, last name)</p>
  
  <p>3) There is also the obligatory paging (page size and page number) as well as sorting</p>
  
  <p>When the user accesses the page first the Url is simply <strong>/Phonebook</strong>. Now let's say the user is searching for "abc", then the Url becomes <strong>/Phonebook?q=abc</strong>. Then he is sorting ascending by first name, and the Url should become <strong>/Phonebook?q=abc&amp;sort=firstName&amp;order=asc</strong>. </p>
  
  <p>The problem I have is how do I program my view to automatically append/modify the query string so that it still contains previously entered constraints (as in my "abc") query but adjusts/adds new constraints for example if sorting, and then paging etc. is used?</p>
  
  <p>I'd hate to use JS and rewriting the location for this, and rather have the page generate real anchors (a href) after every postback for each sort/page/filter link on my page.</p>
  
  <p>Appreciate your time folks :)</p>