获取内置验证器的验证元数据
如何获取内置验证属性的验证元数据?
我正在尝试在表单上实现字数/字符计数,给出允许的剩余数量。当我自己实现字数验证和元数据(将其添加到AdditionalValues中)时,我可以访问这个罚款,但是花了很长时间寻找我找不到从StringLength属性中获取maximumLength的地方。
How do you get the validation metadata for the built in validation attributes?
I'm trying to implement a word count/character count on a form giving the remaining number allowed. As I am implementing the word count validation and metadata myself (adding it into AdditionalValues) I can access this fine, but having spent ages looking I can't find where to get maximumLength from the StringLength attribute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有内置方法可以从 StringLength 属性获取 maxLength。
您必须使用反射手动找到它,例如:
There is no built in way to get the maxLength from the StringLength attribute.
You have to find it manually using reflection, something like: