title: DisplayName Attribute for complex datatypes in ASP.NET Razor MVC
body: <p>I have a very simple requirement. In MVC4 project I have to show a form with @HTML.labelFor field derives values from attribute fields of a properties of viewmodel class. It works fine for simple properties such as Employee Code how ever it does not work for custom datatypes of person class.</p>
  
  <pre><code>namespace MvcApplication1.Models
  {
    public class EmployeeViewModel
    {
      [Display(Name = "Employee Code:")]
      public string EmpCode { get; set; }
  
      public person PersonInfo { get; set; }
  
      [Display(Name = "Department Name:")]    
      public string Department { get; set; }
    }
  }
  
  namespace MvcApplication1.Models
  {
    public class Person
    {
      [Display(Name = "First Name:")]
      public string FName { get; set; }
  
      [Display(Name = "Last Name:")]
      public string LName { get; set; }
    }
  }
  </code></pre>
  
  <p><code>@Html.LabelFor(m =&gt; Model.EmpCode)</code> shows label correctly as Employee Code:</p>
  
  <p><code>@Html.LabelFor(m =&gt; Model.PersonInfo.FName)</code> shows label incorrectly as FName:</p>
  
  <p><code>@Html.LabelFor(m =&gt; Model.PersonInfo.LName)</code> shows label incorrectly as LName:</p>
  
  <p><code>@Html.LabelFor(m =&gt; Model.PersonInfo.Department)</code> shows label correctly as Department Name:</p>
  
  <p>I am trying to figure out how do I show attribute information for object type properties. Do I have use extension methods?</p>