I came to a solution that works, though I am not sure that it is the best solution possible.
First, to my ViewModel (which is EmployeesViewModel) I added a member of type EmployeeViewModel:
public class EmployeeViewModel
{
public int Id { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
public string Gender { get; set; }
public int? Salary { get; set; }
public int? DepartmentId { get; set; }
[Display(Name = "Department Name")]
public string DepartmentName { get; set; }
}
public class EmployeesViewModel
{
public SelectList Departments { get; set; }
public EmployeeViewModel EmployeeColumnNamesRetriever { get; set; }
}
In the controller, I instantiate my Departments, but not EmployeeColumnNamesRetriever, as I need it only to get its metadata:
EmployeesViewModel employees = new EmployeesViewModel
{
Departments = new SelectList(db.Departments, "Id", "Name"),
};
And in the View:
<th>
@Html.DisplayNameFor(model => model.EmployeeColumnNamesRetriever.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeColumnNamesRetriever.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeColumnNamesRetriever.Gender)
</th>
EmployeeColumnNamesRetriever is null, but it does not matter.
If somebody can suggest something nicer, I would be grateful.