开发者

Problem with DataAnnotations and MVC1: Required attribute is ignoring the ErrorMessage property

开发者 https://www.devze.com 2022-12-12 21:59 出处:网络
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 ignore

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;
    }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消