title: Append to routeValues in HtmlHelper extension method
body: <p>I want to create a simple extension of <code>HtmlHelper.ActionLink</code> that adds a value to the route value dictionary. The parameters would be identical to <code>HtmlHelper.ActionLink</code>, i.e.:</p>
  
  <pre><code>public static MvcHtmlString FooableActionLink(
      this HtmlHelper html,
      string linkText,
      string actionName,
      string controllerName,
      object routeValues,
      object htmlAttributes)
  {
    // Add a value to routeValues (based on Session, current Request Url, etc.)
    // object newRouteValues = AddStuffTo(routeValues);
  
    // Call the default implementation.
    return html.ActionLink(
        linkText, 
        actionName, 
        controllerName, 
        newRouteValues, 
        htmlAttributes);
  }
  </code></pre>
  
  <p>The logic for what I am adding to <code>routeValues</code> is somewhat verbose, hence my desire to put it in an extension method helper instead of repeating it in each view.</p>
  
  <p>I have a solution that seems to be working (posted as an answer below), but:</p>
  
  <ul>
  <li>It seems to be unnecessarily complicated for such a simple task.</li>
  <li>All the casting strikes me as fragile, like there are some edge cases where I'm going to be causing a NullReferenceException or something.</li>
  </ul>
  
  <p>Please post any suggestions for improvement or better solutions.</p>