How to run a script after client validation in asp.net mvc
I am disabling my submit buttons when submitting a form, for preventing the user to 开发者_StackOverflow中文版submit the form multiple times.
$(function ()
{
$("form").submit(function ()
{
$(":submit", this).attr("disabled", "disabled");
});
});
But if the client validation fails I want to enable the button again. I am using asp.net mvc unobtrusive client validation
You can use the jQuery One event as detailed in this answer.
Most solutions to this issue revolve around testing $("form").valid() - you could probably use this in your function to determine whether to disable the submit button.
You have to check if there is any error before disabling the submit button
$('#myform').submit(function () {
if ($(this).find('.input-validation-error').length == 0) {
$(this).find(':submit').attr('disabled', 'disabled');
}
});
Hope it helps!
精彩评论