62,025
社区成员
发帖
与我相关
我的任务
分享
@Html.LabelFor(x => x.ListStudent.First().Name)
@Html.LabelFor(x =>Model.ListStudent.First().Name)
不是集合可以直接点它Name,是集合那就集合随便取第一条student对象再点Name~~Imports System.ComponentModel.DataAnnotations
Class Student
<Display(Name:="姓名")>
Property Name As String
<Display(Name:="年龄")>
Property Age As String
End Class
Module Module1
Sub Main()
Dim s As New Student
s.Name = "张三"
s.Age = 20
For Each item In s.GetType.GetProperties
Dim fieldname = CType(item.GetCustomAttributes(GetType(DisplayAttribute), False)(0), DisplayAttribute).Name
Dim value = item.GetValue(s, Nothing)
Console.WriteLine(fieldname & ": " & value)
Next
End Sub
End Module
姓名: 张三
年龄: 20
请按任意键继续. . .
Type type = GetType(this);
MethodInfo info = type.GetMethod("");
Display[] attrs = (Display[])info.GetCustomAttributes(typeof(Display));
return attrs[0].Name;