Created
February 13, 2013 14:48
-
-
Save einarwh/4945077 to your computer and use it in GitHub Desktop.
Implementation of IClientValidatable.GetClientValidationRules to enable client-side validation in Mkay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerable<ModelClientValidationRule> GetClientValidationRules( | |
ModelMetadata metadata, ControllerContext context) | |
{ | |
var propName = metadata.PropertyName; | |
var builder = new JsonBuilder(propName); | |
var visitor = new ExpVisitor<JObject>(builder); | |
Tree.Accept(visitor); | |
var ast = visitor.GetResult(); | |
var json = new JObject( | |
new JProperty("rule", _ruleSource), | |
new JProperty("property", propName), | |
new JProperty("ast", ast)); | |
var rule = new ModelClientValidationRule | |
{ | |
ErrorMessage = ErrorMessage ?? _defaultErrorMessage, | |
ValidationType = "mkay" | |
}; | |
rule.ValidationParameters["rule"] = json.ToString(); | |
yield return rule; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment