DataAnnotations 和 MVC1 的问题:必需的属性忽略 ErrorMessage 属性
我正在使用 DataAnnotations 验证 linq to sql 实体的属性,属性验证正常,但必需的 [ErrorMessage =“错误消息”] ErrorMessage 属性被忽略,而是我收到默认错误消息。
这是我到目前为止的代码:
[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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查是否是命名空间问题。我只是通过将元数据“buddy”类放入与 Model L2S 类相同的命名空间中来解决我的问题,尽管我认为我已经正确引用了所有内容。我想将元数据类放入它们自己的命名空间中以用于组织目的,但它似乎不喜欢那样。 FWIW,我正在 .net 3.5、VS 2008、MVC 2 RC 上运行。
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.