title: Overflowed (i.e. querystring) RouteData back out of the controller into the view
body: <p>Anyone understand why the following doesn't work? </p>
  
  <p>What I want to do is copy current route data plus whatever I add via an anonymous object into new routedata when forming new links on the view. </p>
  
  <p>For example if I have the parameter "page" as a non route path (i.e. so it overflows the route path and its injected into the method parameter if a querystring is present) e.g. </p>
  
  <pre><code>public ActionResult ChangePage(int? page)  { }
  </code></pre>
  
  <p>and I want the View to know the updated page when building links using helpers. I thought the best way to do this is with the following:</p>
  
  <pre><code>public ActionResult ChangePage(int? page)
  {
       if(page.HasValue)
          RouteData.Values.Add("Page", page);
        ViewData.Model = GetData(page.HasValue ? page.Value : 1);
  }
  </code></pre>
  
  <p>Then in the view markup I can render my next, preview, sort, showmore (any links relevant) with this overload:</p>
  
  <pre><code> public static class Helpers
  {
      public static string ActionLinkFromRouteData(this HtmlHelper helper,  string linkText, string actionName, object values)
      {
          RouteValueDictionary routeValueDictionary = new RouteValueDictionary();
  
          foreach(var routeValue in helper.ViewContext.RouteData.Values)
          {
              if(routeValue.Key != "controller" &amp;&amp; routeValue.Key != "action")
              {
                  routeValueDictionary[routeValue.Key] = routeValue;
              }
          }
  
          foreach(var prop in GetProperties(values))
          {
              routeValueDictionary[prop.Name] = prop.Value;
          }
  
          return helper.ActionLink(linkText, actionName, routeValueDictionary;
  
      }
  
     private static IEnumerable&lt;PropertyValue&gt; GetProperties(object o)
     {
      if (o != null) {
          PropertyDescriptorCollection props = TypeDescriptor.GetProperties(o);
          foreach (PropertyDescriptor prop in props) {
              object val = prop.GetValue(o);
              if (val != null) {
                  yield return new PropertyValue { Name = prop.Name, Value = val };
              }
          }
      }
     }
  
      private sealed class PropertyValue 
      {
          public string Name { get; set; }
          public object Value { get; set; }
      }
  }
  </code></pre>
  
  <p>I have posted the code only to illustrate the point. This doesn't work and doesn't feel right... Pointers? </p>