title: AttributeRouting - Correct way of Getting the Action Name from RouteData
body: <p>I have recently started using attribute routing for my action methods and am struggling in getting the action name (and/or id) from the RouteData. Below is an example of how I use the attrubues like so:</p>
  
  <pre><code>[Route( "Edit/{id:int}" )]
  public ActionResult Edit( int id )
  {
      ...
  }
  </code></pre>
  
  <p>Previously I used the following method as an extension of RouteData to retrieve the value</p>
  
  <pre><code>public static string GetActionName( this RouteData routeData )
  {
      return routeData.Values[ "Action" ] as string;
  }
  </code></pre>
  
  <p>This used to return the action name (in this example "edit"). Now this alway returns null. An inspection of the RouteData dictionary shows that these values seem to no longer be placed in the root of the array but rather in an item keyed "[0] = "MS_DirectRouteMatches".</p>
  
  <p>I am able to access this value in the following manner but due to my limited understanding of how these values are populated I am concerned that, for e.g. routes where there are more than one match, this code will fall over in some cases.</p>
  
  <pre><code>public static string GetActionName( this RouteData routeData )
  {
      if( routeData.Values.ContainsKey( "MS_DirectRouteMatches" ) )
          routeData = ( ( IList&lt;RouteData&gt; )routeData.Values[ "MS_DirectRouteMatches" ] )[ 0 ];
  
      return routeData.Values[ "Action" ] as string;
  }
  </code></pre>
  
  <p>What is the correct way to access the RouteData values populated by AttributeRouting?</p>