title: In ASP.NET MVC 2 - How do I get Route Values into my navigation controller so I can highlight the current link?
body: <p>I'm trying to get the current Route into my navigation controller so I can run comparisons as the navigation menu data is populated.</p>
  
  <p>My Links object is like this:</p>
  
  <pre><code>public class StreamNavLinks
  {
      public string Text { get; set; }
      public RouteValueDictionary RouteValues { get; set; }
      public bool IsSelected { get; set; }
  }
  </code></pre>
  
  <p>In the master page, I'm trying to pass the current route to the nav controller like this:</p>
  
  <pre><code>&lt;% Html.RenderAction(
      "MenuOfStreamEntries", // action
      "Nav", // controller
      new { // parameters for action
          currentStreamUrl = "Blog", 
          currentRoute = ViewContext.RouteData } // get route data to compare in controller
  ); %&gt;
  </code></pre>
  
  <p>The problem that I'm running into is that I can't figure out how to get any of the data out of <code>currentRoute</code>. What is the best technique for getting the values out or <code>currentRoute</code>?</p>
  
  <p>I've tried syntax like this:</p>
  
  <pre><code> currentRoute.Values.routevaluename
  </code></pre>
  
  <p>and</p>
  
  <pre><code> currentRoute.Values[0]
  </code></pre>
  
  <p>But I can't seem to get it to work.</p>
  
  <h2>Edit</h2>
  
  <p>I have also tried placing this code into the action of the navigation controller:</p>
  
  <pre><code>var current = RouteData["streamUrl"];
  </code></pre>
  
  <p>and</p>
  
  <pre><code>var current = this.RouteData["streamUrl"];
  </code></pre>
  
  <p>Both versions give me this error:</p>
  
  <blockquote>
    <p>Error  1   Cannot apply indexing with [] to an expression of >type 'System.Web.Routing.RouteData'  C:\pathtocontroller\NavController.cs    25  27</p>
  </blockquote>
  
  <h2>Edit 2</h2>
  
  <p>It also might be helpful to know the route values that I'm trying to match against:</p>
  
  <pre><code>        routes.MapRoute(null, "", // Only matches the empty URL (i.e. ~/)
                          new
                          {
                              controller = "Stream",
                              action = "Entry",
                              streamUrl = "Pages",
                              entryUrl = "HomePage"
                          }
          );
  
          routes.MapRoute(null, "{streamUrl}/{entryUrl}", // matches ~/Pages/HomePage
                          new { controller = "Stream", action = "Entry" }
          );
  </code></pre>
  
  <p>So, ultimately mydomain.com/blog/blogentry1 would map to the same controller/action as mydomain.com/pages/welcome. I'm not looking for the controller value or the action value, rather I'm looking for streamUrl value and EntryUrl value.</p>