0

考虑我有例如2类:DisplayNameFor类的内部类MVC

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 

我通过瞧到视图,并想访问DisplayNameFor学生姓名的视图:

@Html.DisplayNameFor(Function(m) m.Student.Name) 

但它显示字段名称:“名称”,而不是已分配给它的“全名”的显示名称属性。

我的代码有什么问题?

+0

在MVC中,我们将视图与模型绑定,以便我们可以用这种方式编写代码@ Html.DisplayNameFor(model => model.Student.Name)它将显示为“Full名称” – 2015-04-02 10:05:22

回答

0

好吧...在浪费了几个小时之后,我发现我很想把“属性”放在属性名称中。它应该是“Public Property Name As String =''”而不是“Public Name As String =''”。 ()(((