0

I have a Custom Validator on ASP.net MVC 5. The server code works fine, but my client code doesn't work.

In the client I have this code:

 $.validator.unobtrusive.adapters.add("birth", {}, function (options) {
     options.messages['birth'] = options.message;
 });

 $.validator.addMethod("birth", function (value, element, params) {
     return false;
 });

 $.validator.unobtrusive.parse(document);

The adapter add method work fine because the html tag contains the data-val-birth attribute with the error message indicated in the model, but when I submit the form, the validation doesn't work.

The javascript files are included and all seems to be well done. I've tried everything.

Help, please!

Thanks in advance.

1 Answer 1

1

I solved the problem with this code:

$.validator.unobtrusive.adapters.add("birth", function (options) {
    $.validator.addMethod("data-val-birth", function (value, element, params) {
        return false;
    }, options.message);
});

$.validator.unobtrusive.parse(document);

I'm not convinced, but it works. I will continue researching this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.