【问题标题】:Why IntegerAttribute doesn't resolve the ErrorMessageResourceType?为什么 IntegerAttribute 不能解析 ErrorMessageResourceType?
【发布时间】:2012-06-18 22:20:56
【问题描述】:

我正在做 asp.net MVC3 项目,在我的类模型 (CarModel) 中,我放置了一个 Integer 属性来验证属性 ModelYear,我尝试根据本地化自定义错误消息,我的代码:

[Integer(ErrorMessageResourceName = "OnlyNumberValidator", ErrorMessageResourceType = typeof(AddNewCar))]
public Nullable<int> ModelYear { get; set; }

但它没有接收我的错误消息,只是显示了默认消息“字段 ModelYear 必须是数字”

注意:它适用于必需属性!

【问题讨论】:

    标签: asp.net-mvc-3 localization attributes data-annotations


    【解决方案1】:

    请检查您的参考资料,并确保您在 Nuget 包中使用了 DataAnnotationsExtensions.MvcDataAnnotationsExtensions。如果没有 Mvc 特定库,它将产生与您当前遇到的相同的输出。

    【讨论】:

    • 是的,我正在使用 DataAnnotationsExtensions.Mvc
    猜你喜欢
    • 2020-11-16
    • 1970-01-01
    • 2010-09-19
    • 2012-04-01
    • 1970-01-01
    • 2014-09-08
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多