数据注释可以发现其他注释吗?
我想构建一个扩展的 DisplayAttribute 注释,它可以检测该属性是否具有所需的属性。并且,如果是这样,则需要在名称前面加一个“*”来显示它。
这可能吗?我似乎无法弄清楚如何发现属性中是否存在其他属性。即使有可能,Html.Label
帮助程序会识别它吗?或者我也必须延长它吗?
I would like to build an extended DisplayAttribute
annotation that can detect if the property has the required attribute on it. And, if so and a "* " in front of the name to show it is required.
Is this possible? I can't seem to figure out how to discover if other attributes are present within an attribute. Even if it is possible, will the Html.Label
helper recognize it? Or do I have to extend that as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写自定义的
Html.LabelFor
就足够了。您不需要扩展DisplayAttribute
,因为您无法从属性内访问其他属性。Writing a custom
Html.LabelFor
will be enough. You don't need to extend theDisplayAttribute
as you cannot access other attributes from within an attribute.