views:

288

answers:

1

I'm validating the properties of a linq to sql entity using DataAnnotations, the properties are validating fine but the Required[ErrorMessage="error message"] ErrorMessage attribute is being ignored and instead I'm getting the default error message.

Here's the code I have so far:

    [DisplayName("Nombre")]
    [Required( ErrorMessage = "Este campo es requerido" )]
    public string Name
    {
        get;
        set;
    }

    [Required( ErrorMessage = "Este campo es requerido" )]
    [Range( 0, 1000000, ErrorMessage = "Debe insertar un valor entre {1} y 1,000,000" )]
    public decimal Maximum
    {
        get;
        set;
    }

    [Required( ErrorMessage = "Este campo es requerido" )]
    [Range( 0, 100, ErrorMessage = "Debe insertar un valor entre {1} y {2}" )]
    public byte Periods
    {
        get;
        set;
    }
A: 

Check to see if it's a namespace issue. I just fixed my problem by putting the Metadata "buddy" class into the same namespace as the Model L2S class, even though I thought I had everything referenced properly. I wanted to put the metadata classes into their own namespace for organizational purposes but it didn't seem to like that. FWIW, I'm running on .net 3.5, VS 2008, MVC 2 RC.

Dzejms
Yep, I ran into the namespace issue when I tried to reorganize the files. But that was a whole different issue.With this one the problem seems to be a binding issue and not necessarily a data validation one.
JoseMarmolejos