自定义不引人注目的日期验证器
也许这只是我的思维方式,但我很难理解你应该如何做定制的不引人注目的验证器。 C# 部分很简单,但 jqueryui 适配器是我迷失的地方。
我一直在尝试制作一个验证器,要求日期是过去的一定时间。我用它来进行年龄验证,以确保某人输入的日期是 18 年前的日期。
我最终决定将其设为远程验证器,这样验证在客户端和服务器端都使用相同的代码。尽管如此,我还是对 jquery 感兴趣,以完成这项工作。
我希望数据注释扩展具有日期函数。
Maybe it's just the way my mind works, but I have a very hard time understanding how you're supposed to do custom unobtrusive validators. The C# part is easy enough, but the jqueryui adapters are where i get lost.
I've been trying to make a validator that requires a date to be a certain amount of time in the past. I use this for age validation, to make sure someone has entered a date that is 18 years in the past.
I finally decided to just make it a remote validator, that way the validation uses the same code both client and server side. Still, i'd be interested in the jquery to make this work.
I wish the Data Annotation Extensions had date functions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 Brad Wilson 的博客文章 关于使用 ASP.NET MVC 进行不显眼的验证,包括创建自定义验证器。
基于以下 html(应该是 TextBox 帮助程序的输出)
您可以添加以下 javascript 以在客户端验证内容:
年龄计算器的积分来自 Dave
这里缺少的一件事是全球化,但我认为它已经结束了问题的范围。顺便说一句,使用 jquery Globalize 插件 很容易实现
希望这有帮助
You can find a lot of information in Brad Wilson's blog article about unobtrusive validation with asp.net mvc, including creating custom validators.
Based on the following html (should be the output of the TextBox helper)
You can add the following javascript to get things validated on the client side:
Credits for the age calculator are due to Dave
The one thing missing here is globalization, but I figured it was out of the question's scope. btw very easy to implement using the jquery Globalize plugin
Hope this helps