title: MVC2 find area/controller/action from within custom attribute
body: <p>I am using a partial view on two separate pages and the partial view uses Metadata to get the display names in the form of attributes on the Model (the standard way of doing Metadata).</p>
  
  <p>I need to make the display name context sensitive depending on the page.</p>
  
  <p>To this end I am extending the System.ComponentModel.DisplayNameAttribute and am passing in an array of area/controller/action/resourcefile/resourcestring so that I can pick the correct resource string depending on the context.</p>
  
  <p>My problem is how do I get the area/controller/action from within the following:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using CommonInterfaces.Helpers;
  
  namespace CommonInterfaces.ComponentModel
  {
      [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
      public class ContextSensitiveDisplayName : System.ComponentModel.DisplayNameAttribute
      {
          public class Context
          {
              public string Area { get; set; }
              public string Controller { get; set; }
              public string Action { get; set; }
              public Type ResourceType { get; set; }
              public string ResourceKey { get; set; }
  
              public Context(string area, string controller, string action, Type resourceType, string resourceKey)
              {
                  this.Area = area;
                  this.Controller = controller;
                  this.Action = action;
                  this.ResourceType = resourceType;
                  this.ResourceKey = resourceKey;
              }
          }
  
          public ContextSensitiveDisplayName(params Context[] contexts)
          {
              /* Its these values that I need */
              string currentArea = ""; 
              string currentController = "";
              string currentAction = "";
  
              Context selectedContext = 
                  contexts.FirstOrDefault(m =&gt; 
                      (m.Area == currentArea) &amp;&amp; 
                      (m.Controller == currentController) &amp;&amp; 
                      (m.Action == currentAction)
                  );
  
              this.DisplayNameValue = ""; // Use the selectContext to retrieve string from resource file.
          }
      }
  }
  </code></pre>
  
  <p>Any help with this would be greatly appreciated. </p>