I have a senario where i have to check for a Username existance in database while doing a registration page. for this i have implemented a Remote Attribute for remote validation in my model
[Remote("CheckUserNameAvaliable", "User", Httpmethod="Post")]
public string Username {get; set;}
and my method looks like this
[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 made a key up on the username Textbox it will file this remote validation, but according to my requirement i have to fire this remote validation only after entering value in the username Textbox. For that can we forcefully add a delay to the remote validation attribute?
Do anyone know how to add delay to remote validation in MVC3?
I have been caught on similar problems before with MVC3 and remote validation. Guess you want the event to fire on blur but not sure how you'd tell the remote validation that..
Hopefully this will help