Problem with DataAnnotation

0

I have a problem with a custom DataAnnotation.

public class RequiredInt32 : ValidationAttribute
{
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        if (value != null)
        {
            if (Convert.ToInt32(value) == 0)
            {
                return new ValidationResult("MENSAJE_PERSONALIZADO");
            }
        }
        return ValidationResult.Success;
    }
}

I have that code. It turns out that if it enters if , it does not return MENSAJE_PERSONALIZADO returns El campo no es válido . For me to return the message I want, I need to put it explicitly.

[RequiredInt32(ErrorMessage = @"MENSAJE_PERSONALIZADO")]

What is wrong with me and how can I have a default message? Thanks!

    
asked by avechuche 12.10.2016 в 02:59
source

0 answers