Adding delay to the Remote validation MVC3 attribute

I have senario where I have to check for a username in the database by doing a login page. for this, I used Remote Attribute for remote validation in my model

[Remote("CheckUserNameAvaliable", "User", Httpmethod="Post")]
public string Username {get; set;}

and my method is as follows

[HttpPost]
public JsonResult CheckUserNameAvaliable(string UserName)
{
    SessionUser currentUser = this.sessionHelper.GetCurrentUser();
    User user = this.userService.GetByUsername(UserName);
    if (user != null && user.Id != currentUser.Id)
    {
        return Json(false);
    }

    return Json(true);
}

It works fine for me, but the problem is that whenever we entered the key in the Textbox username, it will pass this remote check, but according to my requirement, I should start this remote check only after entering the value in the username Text box To do this, can we force the delay to be added to the remote check attribute?

Does anyone know how to add delay for remote validation in MVC3?

+5
3

MVC3 . , , , , , ..

,

ASP.NET ?

+2

MVC3 jquery.validate . jquery.validate , .

, onkeyup , keyup. , , ajax, , .

, , validator.settings.onkeyup = false, onkeyup , . , , , , .

onkeyup . , false true . , , $.validator.

javascript , MVC. . jquery.validate 1.9.0 , IE 7 8 (, ):

    $("form input[data-val-remote-url]").on({
        focus: function () {
            $(this).closest('form').validate().settings.onkeyup = false;
        },
        blur: function () {
            $(this).closest('form').validate().settings.onkeyup =
                $.validator.defaults.onkeyup;
        }
    });
+3

, , this - ,

0
source

All Articles