title: How to change the display text in the View?
body: <p>I am having the following tables created in my <code>SQL Server</code>:</p>
  
  <pre><code>Create Table tblDepartment(
      Id int primary key identity,
      Name nvarchar(50)
  )
  
  Create table tblEmployee(
      EmployeeId int primary key identity,
      Name nvarchar(50) not null,
      Gender nvarchar(10) not null,
      City nvarchar(50),
      DepartmentId int not null foreign key references tblDepartment(Id)
  )
  </code></pre>
  
  <p>As you can see, </p>
  
  <ol>
  <li>The <code>DepartmentId</code> column in the <code>tblEmployee</code> is the foreign key for the <code>tblDepartment</code> <code>Id</code> column. It is one-to-many relationship: each <code>Department</code> can have many <code>Employee</code></li>
  <li>Both <code>tblDepartment</code> and <code>tblEmployee</code> have <code>Name</code> column</li>
  </ol>
  
  <p>Then in my <code>MVC</code> application, using the two tables, I automatically generate the following <code>EmployeeDataModel.edmx</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/NYtoK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NYtoK.png" alt="enter image description here"></a></p>
  
  <p>(Note that I replace the name <code>tblEmployee</code> with <code>Employee</code> and <code>tblDepartment</code> with <code>Department</code>)</p>
  
  <p>And naturally, I have the following auto-generated entity classes:</p>
  
  <pre><code>public partial class Employee
  {
      public int EmployeeId { get; set; }
      public string Name { get; set; }
      public string Gender { get; set; }
      public string City { get; set; }
      public int DepartmentId { get; set; }
  
      public virtual Department Department { get; set; }
  }
  
  public partial class Department
  {
      public Department()
      {
          this.Employees = new HashSet&lt;Employee&gt;();
      }
  
      public int Id { get; set; }
      public string Name { get; set; }
  
      public virtual ICollection&lt;Employee&gt; Employees { get; set; }
  }
  </code></pre>
  
  <p>Now, the main <code>&lt;table&gt;</code> in my <code>Employee/Index.cshtml</code> <code>View</code> looks like this:</p>
  
  <pre><code>... using here
  @model IEnumerable&lt;Employee&gt;
  ...
  
  &lt;table class="table" border="1"&gt;
      &lt;tr&gt;
          &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Name)&lt;/th&gt;
          &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Gender)&lt;/th&gt;
          &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.City)&lt;/th&gt;
          &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Department.Name)&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
      @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Name)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Gender)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.City)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Department.Name)&lt;/td&gt;
              &lt;td&gt;
                  @Html.ActionLink("Edit", "Edit", new { id = item.EmployeeId }) |
                  @Html.ActionLink("Details", "Details", new { id = item.EmployeeId }) |
                  @Html.ActionLink("Delete", "Delete", new { id = item.EmployeeId })
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  
  <p>Note that in the table headers, I have two "Name"s:</p>
  
  <pre><code>&lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Name)&lt;/th&gt;
  ....
  &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Department.Name)&lt;/th&gt;
  </code></pre>
  
  <p>Which would both show "Name", fitting with the <code>tblEmployee</code> and <code>tblDepartment</code> real column names in the database. I want to avoid that, so I create a <code>partial class</code> for the <code>Department</code> to display the <code>tblDepartment</code> <code>Name</code> as <code>Department Name</code>:</p>
  
  <pre><code>[MetadataType(typeof(DepartmentMetaData))]
  public partial class Department {
  }
  
  public class DepartmentMetaData {
      [Display(Name="Department Name")]
      public string Name { get; set;}
  }
  </code></pre>
  
  <p>And this one is successful:</p>
  
  <p><a href="https://i.stack.imgur.com/96d2C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/96d2C.png" alt="enter image description here"></a></p>
  
  <p>But now, I have another <code>View</code>: <code>Employee/Create.cshtml</code>:</p>
  
  <pre><code>&lt;div class="form-horizontal"&gt;
      &lt;h4&gt;Employee&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Name, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.Name, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Gender, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("Gender", new List&lt;SelectListItem&gt; {
                   new SelectListItem {Text="Male", Value="Male"},
                   new SelectListItem{Text="Female", Value="Female"}
               }, htmlAttributes: new { @class = "form-control" })
              @Html.ValidationMessageFor(model =&gt; model.Gender, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.City, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.City, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.City, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.DepartmentId, "DepartmentId", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("DepartmentId", null, htmlAttributes: new { @class = "form-control" })
              @Html.ValidationMessageFor(model =&gt; model.DepartmentId, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And note that I have a field for <code>DepartmentId</code> with the <code>DropdownList</code>:</p>
  
  <pre><code>    &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.DepartmentId, "DepartmentId", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("DepartmentId", null, htmlAttributes: new { @class = "form-control" })
              @Html.ValidationMessageFor(model =&gt; model.DepartmentId, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Just as for my <code>Employee/Index.cshtml</code> <code>View</code>, this time, I do not want to display <code>DepartmentId</code> <code>Label</code> as <code>"DepartmentId"</code>, thus I create another <code>partial class</code> for <code>Employee</code> to display <code>"DepartmentId"</code> as <code>"Department Name"</code>:</p>
  
  <pre><code>[MetadataType(typeof(EmployeeMetaData))]
  public partial class Employee {
  }
  
  public class EmployeeMetaData {
      [Required]
      public string Name { get; set; }
      [Required]
      public string Gender { get; set; }
      [Required]
      public string City { get; set; }
      [Required]
      [Display(Name="Department Name")] //here it is
      public int DepartmentId { get; set; }
  }
  </code></pre>
  
  <p>But when rendered, my <code>Employee/Create.cshtml</code> <code>View</code> still shows <code>DepartmentId</code> as its <code>Label</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/40pWy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/40pWy.png" alt="enter image description here"></a></p>
  
  <p>Why is that so? How can I display the <code>Label</code> as <code>Department Name</code> too?</p>
  
  <p>Note: all <code>Views</code> (<code>Index</code> and <code>Create</code>) are auto generated when I create <code>EmployeeController</code> with Scaffolding option: <code>MVC5 Controller with views using Entity Framework</code></p>
  
  <p>I use <code>Entity Framework 6.1.1</code> and <code>VS2013</code> if they matter.</p>