I'm trying Remote validation on MVC3 for an user name input text on a register form, everything work ok except that I'm expecting the remote validation trigger when the input lost focus but it is triggering on every key-press or key-up that is written in the input, resulting in many request to the action validation many as every character you write.
There are any way to change this behaviour using the build in unobtrusive javascript.
This is how my property model look like:
[Required]
[Display(Name = "User Name")]
[Remote("ValidateUniqueUserName", "Account")]
public string UserName { get; set; }
this is how the controller looklike:
public JsonResult ValidateUniqueUserName(string username)
{
if (string.IsNullOrEmpty(username))
{
return Json("User Name is required", JsonRequestBehavior.AllowGet);
}
var result = _membershipApplicationService.IsUserNameAvalible(username);
if (!result)
{
return Json("User Name is already taken, please try another one", JsonRequestBehavior.AllowGet);
}
return Json(true, JsonRequestBehavior.AllowGet);
}
And the register form is rendered using a @Html.Partial
thanks.