简体   繁体   中英

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 . I'm using the IClientValidatable since I had to create a custom validator for my scenario. But if I apply the validator to each of the properties, I will get 3 times the error message. 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:

$("#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. Thanks

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

你有没有试过:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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