Ejemplo n.º 1
0
 protected static string CreateFieldName(TemplateDescriptor descriptor,
                                         string expression, string member)
 {
     return((String.Equals(expression, member, StringComparison.OrdinalIgnoreCase))
                         ? descriptor.Prefix
                         : descriptor.GetHtmlElementName(member));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the collection of client validation rules,
        /// which are applied to the property of the
        /// model, accessed through the specified <paramref name="expression"/>.
        /// </summary>
        /// <param name="modelName">Specifies the name of the model,
        /// which will prefix the validation rule member name.</param>
        /// <param name="expression">A string expression to access the
        /// model property.</param>
        public FormValidationMetadata Rules(string modelName, string expression)
        {
            TemplateDescriptor descriptor = new TemplateDescriptor(
                Context.ViewData.Template.Type)
            {
                Prefix = modelName
            };

            descriptor.Prefix = descriptor.GetHtmlElementName(expression);

            return(new FormValidationMetadata(
                       CreateClientRules(GetRulesInternal(expression))
                       .Each(r => {
                r.Field = CreateFieldName(descriptor, expression, r.Field);
            })));
        }