Know if there were validation errors in the form in MVC 3

I have a form that I submit via AJAX. It uses standard MVC checking. When the user first loads the page, this form is hidden. It appears only after users click on the button on the page.

I want to know if there is a way to find out - in the view - if there were errors in the check. So, the next time the form is displayed, the form is displayed and is not hidden.

+3
source share
1 answer

You might know it like this:

if ($('#someFormId').valid()) {
    // the form is valid
} else {
    // the form contains validation errors
}

or if you want to check if there are any mode errors in the view:

@if (ViewData.ModelState.IsValid)
{
    // there are no errors to display
} else {
    // there were validation errors
}
+7
source

All Articles