【发布时间】:2015-04-02 08:58:41
【问题描述】:
假设我有 2 个类,例如:
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)
但它显示字段名称:“名称”而不是已分配给它的显示名称属性“全名”。
我的代码有什么问题?
【问题讨论】:
-
在 MVC 中,我们将视图与模型绑定,这样我们也可以用这种方式编写代码 @Html.DisplayNameFor(model=>model.Student.Name) 它将显示为“全名”
标签: asp.net-mvc asp.net-mvc-3 model-view-controller data-annotations