设置 MVC3 验证消息的样式

发布于 2024-12-21 09:23:02 字数 199 浏览 3 评论 0原文

我喜欢 MVC3 中的默认验证消息,但现在我正在转向一些更大的表单,表单元素需要更紧密地组合在一起。这会导致生成的默认验证消息出现问题。它们要么换行,导致一半消息出现在表单元素下,要么完全破坏我的表单布局。

有没有人有一个好的解决方案来解决这个问题?

您认为将验证消息设置为“工具提示”会有帮助吗?很想听听您的建议和解决方案。

问候保罗

I love the default validation messages in MVC3 but now I am moving onto some much larger forms the form elements need to sit a lot tighter together. This causes issues with the default validation messages produced. They either wrap, leading to half the message appearing under the form element, or break my form layout completely.

Does anyone have a good solution to this problem?

Would setting the validation message to being a 'tooltip' help do you think? Would love to hear your suggestions and solutions.

Regards Paul

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

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

发布评论

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

评论(2

雨落□心尘 2024-12-28 09:23:02

默认验证消息是 SPAN。如果您想使用不同的元素(例如IMG),则需要创建自定义验证消息扩展。查看 MVC 中的 ValidationMessageHelper 方法,了解默认的 SPAN 是如何构建的。我认为您可以重用 data-valmsg-for 等自定义属性。另外,假设您使用的是非侵入式 ajax 验证,则需要修改jquery.validate.unobtrusive.js

The default validation message is a SPAN. If you want to use a different element (e.g. IMG), you would need to create a custom validation message extension. Check out ValidationMessageHelper method in MVC to get an idea how the default SPAN is built. I think you can reuse the custom attributes like data-valmsg-for. Also, you need to modify the jquery.validate.unobtrusive.js assuming you are using unobtrusive ajax validation.

笑,眼淚并存 2024-12-28 09:23:02

这完全取决于您的布局。您可以将 ValidationMessage 放在您想要的任何位置,并按照您想要的方式设置其样式。只需查看输出 HTML 并弄清楚如何按照您想要的方式布局消息即可。

This is all dependant upon your layout. You can put the ValidationMessage anywhere you want, and style it any way you want. Just look at the output HTML and figure out how to lay out the message how you want it.

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