在 mvc 2 中本地化默认模型验证

发布于 2024-09-07 14:34:10 字数 211 浏览 4 评论 0原文

[Required]
[DisplayName("my date")]
public DateTime? DateReg { get; set; }

因此,如果用户要传递无效的日期时间值,他将收到此消息 “值‘02.07.201022’对于我的日期无效。”

我该如何翻译/本地化此消息?

[Required]
[DisplayName("my date")]
public DateTime? DateReg { get; set; }

so if the user is going to pass in an invalid datetime value he will get this message
"The value '02.07.201022' is not valid for my date."

how can I translate/localize this message ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰ツ都不明白 2024-09-14 14:34:11

App_GlobalResourcesGlobal.asax 中的 Application_Start 中添加 Messages.resx

DefaultModelBinder.ResourceClassKey = "Messages";

然后在 Messages 中添加 Messages.resx。在 resx 文件中,您可以定义以下字符串:

PropertyValueInvalid: The value {0} is invalid for the property {1}

该键需要被称为 PropertyValueInvalid

Add Messages.resx in App_GlobalResources and in Application_Start in Global.asax:

DefaultModelBinder.ResourceClassKey = "Messages";

Then in the Messages.resx file you could define the following string:

PropertyValueInvalid: The value {0} is invalid for the property {1}

The key needs to be called PropertyValueInvalid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文