MVC3 IValidatableObject 日期
我有一个带有日期字段的基本表单,我想在 IValidatableObject
内验证它。该字段的类型映射到 DateTime 属性,因此如果有人输入 26/15/2011,您如何在 Validate 方法中选取它?严格来说,这几乎就像用 DateTime 验证 DateTime 对象一样,这是没有意义的。关于如何解决这个问题或如何检测日期错误的任何想法?
I have a basic form which has a date field and I want to validate it inside the IValidatableObject
. The type of the field is mapped to a DateTime property so if someone types in 26/15/2011, how do you pick that up in the Validate method? Strictly speaking its almost like validating a DateTime object with a DateTime which doesn't make sense. Any ideas on how to get around this or how to detect that its the wrong date?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的方法上实现 IValidatableObject 并对此字段进行验证,
例如
我建议在客户端使用 jquery validate 和 jqueryUI calendar
希望有帮助
Implement IValidatableObject on your method and make the validation for this field
e.g.
I suggest to use jquery validate and jqueryUI calendar for client side
Hope it helps