Search code examples
asp.net-mvc-2enterprise-library

Entlib validation ErrorMessage not working with MVC ValidationMessageFor


I'm using the combination described on the title. If I use DataAnnotations the ErrorMessage I set is shown correctly on MVC 2 form validations. However if I switch the validation to Entlib 5, with the same ErrorMessage property set, the error message shown is a deafult one, depending on the validator, and not the one I set.

Before, working:

[Required(ErrorMessage="The field name is required.")]
public virtual string Name { get; set; }

After:

[NotNullValidator(ErrorMessage="The field name is required.")]
public virtual string Name { get; set; }

Thanks.


Solution

  • I was actually setting the wrong property for this one.

    Instead of

    [NotNullValidator(ErrorMessage="The field name is required.")]
    public virtual string Name { get; set; }
    

    it should be

    [NotNullValidator(MessageTemplate="The field name is required.")]
    public virtual string Name { get; set; }