【问题标题】:DisplayNameFor Class Inside Class MVCDisplayNameFor Class Inside Class MVC
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-03
    • 2016-08-28
    • 2014-10-30
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    相关资源
    最近更新 更多