ASP.Net MVC3 Remote Data Annotation Not Working -
i have class data annotations using remote attribute:
public class person { [remote("namevalidation","validation", errormessage = "field invalid", fields = "lastname")] public string firstname { get; set; } public string lastname { get; set; } }
in validationcontroller:
public actionresult namevalidation(string firstname, string lastname) { bool isnamevalid = true; if (firstname.contains("john") && lastname.contains("doe")) { isnamevalid = false; } return json(isnamevalid, jsonrequestbehavior.allowget); }
in view have:
@{html.enableclientvalidation(); } @using (html.beginform()) { @html.editorfor(x => x.firstname) @html.validationmessagefor(x => x.firstname) @html.editorfor(x => x.lastname) @html.validationmessagefor(x => x.lastname) <input name="finishbutton" type="submit" id="button" > }
the namevalidation gets called if add required attribute this:
public class person { [required] [remote("namevalidation","validation", errormessage = "field invalid", fields = "lastname")] public string firstname { get; set; } public string lastname { get; set; } }
how remote validation work without having have required validation?
update mvc3 rc2. tried without required attribute. working. 1 thing found strange though, remote validation fired on every key press , onchange other times
Comments
Post a Comment