开发者

How to show the ajax loader image while remote validating using data annotation in asp.net mvc3

in my asp.net mvc3 application i am doing remote validation if a user already exist using data annotation . it is working perfectly . i was wondering if there is any why i can show the ajax loader image beside the开发者_如何学编程 input field in the form while remote validation(ajax request) is taking place.

please help me

Thanks


I don't think you can do it without writing the validation code yourself.

See this article: http://www.highoncoding.com/Articles/767_Remote_Validation_in_ASP_NET_MVC_3.aspx

Within the AJAX call you would have to add a beforeSend to display the image, then hide it on complete.


You can use $.ajaxStart .ajaxStop for this purpose:

$("#yourRegisterFormToValidate")
          .ajaxStart(function () { $(".loader").show(); })
          .ajaxStop (function () { $(".loader").hide(); });


If that was me, I would want to stop user from entering data into any other fields until this is validated, therefore I would use AjaxOptions to specify animation and duration of that animation.

I'd have something on the lines of:

@{
    AjaxOptions ajaxOpts = new AjaxOptions
    {
        UpdateTargetId = "updateDiv",
        LoadingElementId = "myImg",
        LoadingElementDuration = 2000,        
        HttpMethod = "GET"        
    };    
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜