问题
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