error message not displaying

Jan 10, 2012 at 3:18 PM

Ive created a custom validator but for some reason the error message wont display

 

public class CodeRequiredAttribute : ModelAwareValidationAttribute
    {
        //this is needed to register this attribute with foolproof's validator adapter
        static CodeRequiredAttribute() { Register.Attribute(typeof(CodeRequiredAttribute)); }

        private string _propertyName;
        
        public CodeRequiredAttribute(string propertyName) : base()
        {
            _propertyName = propertyName;
        }

        public override bool IsValid(object value, object container)
        {
            Type type = value.GetType();
            PropertyInfo propertyInfo = type.GetProperty(_propertyName);
            Object val = propertyInfo.GetValue(value, null);
            if (val == null)
            {
                return false;
            }
            else if ((Guid)val == Guid.Empty)//empty Guid
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }

 

in my data layer i have a partial class (which extends the customer data object)

[DisplayName("Marital Status")]
        [CodeRequiredAttribute("CodeID", ErrorMessage = "A marital status is required")]
        public Code MaritalStatusCode { get; set; }

the custom validation code is executed correctly, but no errormessage is displayed.


in the page

<%=Html.ValidationMessageFor(m => m.Customer.MaritalStatusCode)%>