如何在验证消息前面的验证摘要中获取错误字段的 ID
有没有办法自定义validationSummary,以便它可以输出锚标记,其HREF是摘要中验证消息显示的字段的名称?这样,使用 jquery,我可以添加 onclick 事件,当在验证摘要上单击锚标记时,这些事件会聚焦于该字段。
这主要针对视障人士,这样当他们出现错误时,验证摘要会聚焦,他们会选择错误条目,带有字段标签的锚点标签会聚焦,屏幕阅读器会先读取锚点,然后读取消息,然后他们可以单击聚焦在错误的字段上。
名字 - 请输入您的名字。
谢谢。
Is there a way to customize the validationSummary so that it can output anchor tags who's HREF is the name of the field that the validation message in teh summary is displaying for? This way, using jquery, i can add onclick events that focus the field when the anchor tag is clicked on the validation summary.
This is primarely for visually impaired people, so that when they have errors, the validation summary focuses, they tab to an error entry, the anchor tag with the field label focuses and the screen reader reads the anchor then the message, then they can click on the anchor to focus on the erroneous field.
<a href="#First_Name">First Name</a> - Please enter your first name.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为框架内没有任何功能,因此您需要使用自定义扩展方法。例如:
这是使用框架内现有的扩展方法并更改插入列表中的标签。这是一个快速示例,在使用它之前需要考虑一些事情:
html.ValidationMessage
。如果您需要对消息进行编码,那么您需要包含代码以提供默认消息和任何本地化要求。html.ValidationSummary()
,那么您需要创建相关签名并调用所提供的方法。I don't think that there is any functionality within the framework for this so you would need to use a custom extension method. For example:
This is using the existing extension method from within the framework and changing the tag that is inserted into the list. This is a quick sample and there are some things to consider before using this:
html.ValidationMessage
. If you need to encode the message then you would need to include so code to provide default messages and any localization requirements.html.ValidationSummary()
then you would need to create the relevant signatures and call to the method provided.