I have a form that I submit via AJAX. It is using the sta开发者_运维知识库ndard MVC validation. When the user first loads the page, this form is hidden. It only appears after the users click on a button in the page.
I want to know if there is a way to know --in the view-- if there were errors in the validation. So, the next time the form is displayed, the form is being shown and not hidden.
You could know it like this:
if ($('#someFormId').valid()) {
// the form is valid
} else {
// the form contains validation errors
}
or if you wanted to test if there are some mode errors in the view:
@if (ViewData.ModelState.IsValid)
{
// there are no errors to display
} else {
// there were validation errors
}
精彩评论