标签: c# asp.net-mvc asp.net-mvc-3 data-annotations
我想构建一个扩展的DisplayAttribute注释,它可以检测属性是否具有必需的属性。并且,如果是这样,并且在名称前面显示“*”以显示它。
DisplayAttribute
这可能吗?我似乎无法弄清楚如何发现属性中是否存在其他属性。即使有可能,Html.Label帮助者会认出它吗?或者我也必须扩展它?
Html.Label
答案 0 :(得分:1)
编写自定义Html.LabelFor就足够了。您无需扩展DisplayAttribute,因为您无法从属性中访问其他属性。
Html.LabelFor