如何更改所有int字段的消息,而不是说:
The field must be a number 用英文表示:
El campo tiene que ser numerico 在西班牙语中.
有办法吗?
validation asp.net-mvc localization numbers data-annotations
有一种方法可以将默认资源设置为数据注释验证吗?
我不想做这样的事情:
[Required(ErrorMessage="Name required.", ErrorMessageResourceType=typeof(CustomDataAnnotationsResources)]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
Global.asax中
DataAnnotations.DefaultResources = typeof(CustomDataAnnotationsResources);
Run Code Online (Sandbox Code Playgroud)
然后
[Required]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)
有人给我一个光!
提前致谢
编辑
我真正的问题是使用EF Code First CTP4.CTP5修复它.谢谢大家.
.net asp.net-mvc-2-validation data-annotations asp.net-mvc-2
我需要替换模型状态资源(到另一种语言).
我已经看到了上述问题的一些答案,但不幸的是我无法让它发挥作用.任何详细的答案或例子都会受到批评.
谢谢.
我正在使用System.ComponeneModel.DataAnnotations属性,例如Required和StringLength.是否可以全局本地化其错误消息?
我知道我能做到这一点
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Resources.Validation))]
Run Code Online (Sandbox Code Playgroud)
但到处都这样,我使用必需的属性将是疯狂的.另外我想避免像这样的东西:
public class LocalizedRequiredAttribute : RequiredAttribute {
public LocalizedRequiredAttribute()
: base() {
ErrorMessageResourceName = "Required";
ErrorMessageResourceType = typeof(Resources.Validation);
}
}
Run Code Online (Sandbox Code Playgroud)
(但如果没有其他办法,我会满足于此)
validation attributes localization data-annotations asp.net-mvc-3
asp.net-mvc ×2
localization ×2
validation ×2
.net ×1
attributes ×1
file ×1
modelstate ×1
numbers ×1
resources ×1