开发者

ASP.NET MVC client side validation with jQuery 'loading' image function

I have a jQuery function that shows a 'loading' image and disable the submit button when the form is submitted. I also added Html.EnableClientValidation();

The problem is that when I click the submit button and the form is not valid then I get all the validation error messages but th开发者_开发技巧e 'loading' image never stops and the button stays 'disabled'

I want to add functionality that stops the 'loading' image and enables the button when the form is not valid.

I know how to write the jQuery function but I don't know how to integrate it with MVC EnableClientValidation.


I suppose that you are using an AJAX form because you are talking about disabling and enabling the submit button, In this case I would recommend you disabling the submit button just before sending the AJAX request which will ensure that client validation has passed.

If you are using MS AJAX to AJAXify your form the two events you might try are OnBegin and OnComplete:

<% Ajax.BeginForm(new AjaxOptions { 
    OnBegin = "enable" OnComplete = "disable" }) %>

If you are using jquery then you could subscribe for the beforeSend and complete events and this could be achieved globally with $.ajaxSetup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜