Asp.net mvc 类MVC中类的DisplayName

Asp.net mvc 类MVC中类的DisplayName,asp.net-mvc,asp.net-mvc-3,model-view-controller,data-annotations,Asp.net Mvc,Asp.net Mvc 3,Model View Controller,Data Annotations,假设我有两个班级,例如: Class ClsStudent Public Id As System.Nullable(Of Integer) <Required(AllowEmptyStrings:=False)> _ <StringLength(45, ErrorMessage:="Name must not exceed 45 characters.")> _ <Display(Name:="Full Name", Descriptio

假设我有两个班级,例如:

Class ClsStudent
   Public Id As System.Nullable(Of Integer)

   <Required(AllowEmptyStrings:=False)> _
   <StringLength(45, ErrorMessage:="Name must not exceed 45 characters.")> _
   <Display(Name:="Full Name", Description:="Student full name.")> _
   Public Name As String = ""
End Class

Class Voila
   Public Student As ClsStudent
   Public Status As Boolean
End Class
但它会显示字段名:name,而不是指定给它全名的display name属性


我的代码怎么了?

好吧……在浪费了几个小时之后,我才发现我没有将属性添加到属性名称中。它应该是公共属性名String=,而不是公共名称String=。Fewss…:

在MVC中,我们将视图与模型绑定,这样我们也可以用这种方式编写代码@Html.DisplayNameFormodel=>model.Student.Name它将显示为全名
@Html.DisplayNameFor(Function(m) m.Student.Name)