c# – 在类上使用DisplayAttribute
发布时间:2020-12-15 08:34:19 所属栏目:百科 来源:网络整理
导读:因为我们可以使用System.ComponentModel.DataAnnotations.DisplayAttribute为属性设置标签,我想将它用于类,但不允许在类上使用它. using System.ComponentModel.DataAnnotations;[Display(Name = "A person")]public class Person{ [Display(Name = "A name"
因为我们可以使用System.ComponentModel.DataAnnotations.DisplayAttribute为属性设置标签,我想将它用于类,但不允许在类上使用它.
using System.ComponentModel.DataAnnotations; [Display(Name = "A person")] public class Person { [Display(Name = "A name")] public string Name { get; set; } } 有人知道解决方法吗? 编辑: @model Models.Person <fieldset> <legend>Person</legend> <div class="display-label"> @Html.LabelFor(model => model.Name) </div> </fieldset> 我想做一些类似于Name属性的事情. 解决方法
DisplayName属性(来自System.ComponentModel)执行类似的功能,可以应用于类.
MSDN (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |