我见过很多类似的问题,但似乎都没有直接的答案。当我尝试将 Display(Name) 属性添加到外键字段时,显示名称未显示在“创建”、“编辑”、“删除”和“详细信息”表单上。我也尝试将属性放在导航属性上:
[Display(Name="Gender")]
public virtual Gender Gender {get; set;}
但这也没有用。
public class Person
{
public int ID {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
[Display(Name="Gender")]
public int GenderID {get; set;}
public virtual Gender Gender {get; set;}
}
public class Gender
{
public int ID {get; set;}
public string GenderName {get; set;}
public virtual ICollection<Person> People {get; set;}
}