MVC 验证错误消息未硬编码在属性中

发布于 2024-08-12 09:02:47 字数 177 浏览 6 评论 0 原文

我要求传递到我的视图的验证错误消息来自数据库。

我想在我的模型上使用数据注释,但验证属性中的错误消息键只能是字符串或常量。

我愿意接受其他验证解决方案,但我需要从数据库中提取错误消息。

如果错误消息不是字符串,是否还有其他有效的验证解决方案?现在我正在考虑使用 T4 生成常量文件......

I have a requirement that the validation error messages that are passed to my view come from the database.

I want to use data annotation on my model but the error message key in validation attributes can only be a string or a constant.

I'm open to other solutions for validation but I need to pull the error messages from the database.

Are there any other ellegent solutions for validation were the error message is not a string? Right now I am thinking about using T4 to generate a constants file...

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

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

发布评论

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

评论(2

梦毁影碎の 2024-08-19 09:02:47

您可以使验证运行程序过载,以将错误消息与数据库中的错误消息交换。

You could overload the validation runner to swap out error messages with ones from a database.

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