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

余生颓废 提交于 2019-12-11 11:32:17

问题


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


回答1:


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.




回答2:


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

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



回答3:


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"        
    };    
}


来源:https://stackoverflow.com/questions/6688668/how-to-show-the-ajax-loader-image-while-remote-validating-using-data-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!