title: Passing one parameter of multiple to controller
body: <p>I'm trying to sort a list while maintaining the page number currently being viewed. I've created a pagehelper class and sorthelper class to do so. The problem is that instead of passing just the parameter the controller needs it's passing the entire end of the URL. How do I route it so that just the correct parameter is passed?</p>
  
  <p>sorthelper.cs:</p>
  
  <pre><code>public static MvcHtmlString PageSort
      (this HtmlHelper html, string LinkText, string sortOrder, string Category, PagingInfo pagingInfo, Func&lt;int, string&gt; pageUrl)
  {
      //Ref to Models.PagingInfo to get number of pages
  
      StringBuilder result = new StringBuilder();
      {
  
          //Constructs the href per page
          TagBuilder tag = new TagBuilder("a"); // Construct an &lt;a&gt; tag
  
          tag.MergeAttribute("href", "?sortOrder=" + sortOrder + pageUrl(pagingInfo.CurrentPage));
  
          tag.InnerHtml = LinkText;
  
          tag.AddCssClass("selected");
          result.Append(tag.ToString());
      }
  
      //Dynamically creates links - String as href+pagenumber=URL
      return MvcHtmlString.Create(result.ToString());
  }
  </code></pre>
  
  <p>Link from Entries.cshtml:</p>
  
  <pre><code> @Html.PageSort("Case", "Case", Model._CurrentCategory, Model.PagingInfo, x=&gt; Url.Action("Entries",
              new { page = Model.PagingInfo.CurrentPage, category = Model._CurrentCategory}))
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>        routes.MapRoute(null, "{category}/{sortOrder}/Page{page}", new
      {
          controller = "Entry",
          action = "Entries"
      },
         new { sortOrder = @"\[A-Z]", page = @"\d+" }
      );
  </code></pre>
  
  <p>When I sort I get the following link:</p>
  
  <p>http://<em>SNIP</em>:7511/?sortOrder=Case/?page=1</p>
  
  <p>The parameter needed in this instance would simply be "Case" but instead I'm getting "Case/?page=1".
  My initial thought is to filter the url with a Regex in the controller itself but I have a feeling I'm over-complicating it and possibly not utilizing the routeconfig correctly.</p>
  
  <p>Is this supposed to be handled by routing, the controller, or the helper object? How?</p>
  
  <p>Thanks!</p>
  
  <p><strong><em>EDIT</em></strong>
  Thank you for the information. Apparently I was over-complicating it.</p>
  
  <pre><code>&lt;th&gt;@Html.RouteLink("Case", "", new {category = Model._CurrentCategory, sortOrder = "Case", page = Model.PagingInfo.CurrentPage })&lt;/th&gt;
  </code></pre>
  
  <p>This worked but apparently my db is leaving trailing spaces in all entries so that is a separate issue I will have to tackle.</p>