相关疑难解决方法(0)

如何在ASP.NET MVC中更改默认验证错误消息?

说我的模型中有这个属性:

[DisplayName("test")]
[Required(ErrorMessage = "required")]
public DateTime? SomeDate { get; set; }
Run Code Online (Sandbox Code Playgroud)

当您输入"asdf"时Html.TextBoxFor(model => model.SomeDate),您会收到验证错误消息"值'asdf'对测试无效.".

你如何修改那条消息?ASP.NET MVC被忽略了[DataType(DataType.DateTime, ErrorMessage = 'some other message')]

asp.net-mvc data-annotations asp.net-mvc-2

28
推荐指数
1
解决办法
6万
查看次数

全局本地化验证

我正在使用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

4
推荐指数
1
解决办法
5276
查看次数