问题描述:

I have a ValidationSummary that works pretty well, although it doesn't go away after the last of the form errors are rectified.

I'm not sure if this is default behavior or a bug. It seems more towards the latter, since they don't go away after my form has been submitted.

The only thing I suspect might be impacting the functionality is that the form is created through Ajax.BeginForm().

Even still, shouldn't the ValidationSummary disappear right as I hit the submit button?

网友答案:

You can make it hide on form submit in your javascript. If you inspect element on your validation summary, you'll notice it changes styles from .validation-summary-valid to .validation-summary-errors if there are any errors. So this makes it easy to hide.

e.g.

$('#formName').submit(function() {
    if ($(this).valid()) { // checks form is valid.
        $('.validation-summary-errors').hide(); // hides it
    }
});
网友答案:

You have not added any code so its hard to understand the problem thats why i suggest you to use jQuery Unobtrusive Validation library, it is developed by Microsoft and is included in the ASP.NET MVC framework. here is the example to use it.

相关阅读:
Top