Watch this example on YouTube:
1. Validation
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule
{
ValidationType = "validatecheckbox",
ErrorMessage = "Fix it!"
};
rule.ValidationParameters.Add("fields", string.Join(",", _fields));
yield return rule;
}
2. JS
$.validator.addMethod('validatecheckbox', function (value, element, params) {
debugger
var isValid = true;
if ($(params)[0].fields[1].val() == "True"){
if ($(params)[0].fields[0][0].checked == false) {
isValid = false;
}
}
});
No comments:
Post a Comment