views:

50

answers:

0

Hi All,

I have a data entity class which I have added a property to using a partial class:

 [MetadataType(typeof(LocaleMetaData))]
    partial class Locale
    {
        public sealed class LocaleMetaData
        {

            [Required(AllowEmptyStrings = false, 
                      ErrorMessage = "A locale must have a descriptive name.")]
            public object Name { get; set; }

            [Required(AllowEmptyStrings = false, 
                      ErrorMessage = "A locale must have a valid culture name. ")]
            public object CultureName { get; set; }

            [DefaultValue(true)]
            public object Active { get; set; }
        }

        public bool Selected { get; set; }
    }

I have created a custom validation attribute to check a list of Locale to verify that at least one has the property Selected set true:

 public class PostedTemplateProfile
    {
        [RequiredAtLeastOne(ValidationCriteria = ValidateIf.BooleanTrue,
                            ValidationParam = "Selected",
                            ErrorMessage = "A template must have at least one locale associated with it.")]
        public List<Locale> LocaleAssociations { get; set; }

        public TemplateProfile Template { get; set; }
    }

When I run the code and test a validation failure in the view (by not checking any of the locales in the view) the validation does not append a ModelError for the LocaleAssociations property into the ModelState - yet if I trace the code I see the attribute run with exactly the anticipated behavior and return false from the IsValid derived method override of the attribute...

Probably missing something obvious - but all I can see are trees! Any help appreciated!

-Grant.