MVC 3 specifying validation trigger for Remote validation

asp.net-mvc-3, unobtrusive-validation, validation

Solution

Try

`$.validator.setDefaults({ onkeyup: false });`

It works for me.

Problem

I have implemented remote validation using MVC 3 unobtrusive validation as follows The model ``` public class MyViewModel { [Remote("ValidateAction", "Validation")] public string Text { get; set; } } ``` The Controller ``` public partial class ValidationController : Controller { public virtual JsonResult ValidationAction(string aTextToValidate) { if(aTextToValidate == /* some condition */) return Json(true, JsonRequestBehavior.AllowGet); return Json("This is not valid, Try Again !", JsonRequestBehavior.AllowGet); } } ``` The View ``` @using (Html.BeginForm() { @Html.TextBoxFor(m => m.Text) @Html.ValidationMessageFor(m => m.Text) } ``` And that's it, it all works, but ValidationAction is fired on every key press, which is not ideal, I would like just to fire when the element looses focus, but cannot figure how to do this UPDATE Actually I have noted that, by default, the validation does fire onBlur once .i.e. the first time the element looses focus, however when attempting to correct it, validation then fires onKeyUp. I think this is intended functionality and thinking about it is probably quite useful. However it would be useful to know if it is possible to modify this behaviour

Original source

Related problems