【发布时间】:2013-12-29 16:41:03
【问题描述】:
我有个模特说
public class Contact
{
[Display(Name = "Phone Number", Description = "This is Phone number to contact")]
[Visibility(ShowForDisplay=false)]
public string Phone { get; set; }
[Display(Name = "Mail To Support", Description = "This is Mail for support")]
public string Email { get; set; }
}
现在在 Mvc html 中,我在几个地方做,比如
@Html.DisplayTextFor(x=>x.Phone)
现在我想要一个基于类似这样的属性,它可以在模型级别进行管理,以便将此显示转换为视图。例如 @html.DisplayTextFor(x=>x.Phone) 应该在那里,但是当我做 [Visibility(ShowForDisplay=false)] 时,值或文本的所有可见性都不应该在 html 上呈现。
如何通过自定义属性 [Visibility(ShowForDisplay=false)] 之类的属性来完成?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 custom-attributes