Displaying model state errors after ajax call on Razor views Displaying model state errors after ajax call on Razor views ajax ajax

Displaying model state errors after ajax call on Razor views


You can return errors with Json result (How to get all Errors from asp.net mvc modelState?):

var allErrors = ModelState.Values.SelectMany(v => v.Errors);

Then manually show errors. Get form validator:

var validator = $("form").validate();

Then check that your fields are initialized correctly, for example you can look here (optional step):

validator.settings.rules

OR

validator.settings.messages

If everything is fine, then you could show error:

validator.showErrors({"Password": "Too simple!"});

Where Password is field name and Too simple! is error message.