asp.net mvc 3 - MVC 3 specifying validation trigger for Remote validation -


this question has answer here:

i have implemented remote validation using mvc 3 unobtrusive validation 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 == /* condition */)             return json(true, jsonrequestbehavior.allowget);         return json("this 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, works, validationaction fired on every key press, not ideal, fire when element looses focus, cannot figure how this

update

actually have noted that, default, validation fire onblur once .i.e. first time element looses focus, when attempting correct it, validation fires onkeyup. think intended functionality , thinking quite useful. useful know if possible modify behaviour

try

$.validator.setdefaults({ onkeyup: false });

it works me.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -