简体   繁体   English

使用jQuery不显眼的验证添加组

[英]Adding a group using jQuery unobtrusive validation

I'm using asp.net mvc 3, and I have a scenario like the one in this post JQuery Validate multiple fields with one error . 我正在使用asp.net mvc 3,我有一个类似于这篇文章中的一个场景JQuery验证多个字段,但有一个错误 I'm using the IClientValidatable since I had to create a custom validator for my scenario. 我正在使用IClientValidatable,因为我必须为我的场景创建一个自定义验证器。 But if I apply the validator to each of the properties, I will get 3 times the error message. 但是如果我将验证器应用于每个属性,我将得到错误消息的3倍。 So I know you can use groups to tell the validator to group messages for multiple fields, and I couldn't find an option to do it from C#, so I tried to do something like this: 所以我知道你可以使用组来告诉验证者为多个字段分组消息,我找不到从C#中选择的选项,所以我试着这样做:

$("#frmUser").validate({
    groups: {
        DateofBirth : "Year Month Day"
    }
});

but the whole validation stops working, so I have the feeling that line of code overrides whatever the unobtrusive code generates. 但整个验证停止工作,所以我觉得代码行会覆盖任何不显眼的代码生成的内容。 So I'm wondering if there's a way to set groups in the 所以我想知道是否有办法在中设置群组
validator.unobtrusive.adapters.add or validator.addMethod methods. validator.unobtrusive.adapters.addvalidator.addMethod方法。 Thanks 谢谢

这样的事情可能有所帮助: MVC3不显眼的验证组输入

你有没有试过:

$.validator.setDefaults({ groups: { DateofBirth : "Year Month Day" } });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM