失去焦点时,MVC需要现场验证 [英] MVC required field validation when lost focus

查看:62
本文介绍了失去焦点时,MVC需要现场验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET MVC [必需]验证仅在以下情况之一中触发:
1)提交表单
2)在字段中制表符->输入一些文本->制表符->制表符返回域->删除文本->制表符.

The ASP.NET MVC [Required] Validation only trigger in one of the following conditions:
1) Form submission
2) Tab into the field -> Enter some text -> Tab out -> Tab back into the field -> Remove the text -> Tab out.

我想确定是否以这种方式触发:
Tab进入字段-> Tab out->触发验证

I would like to make if to be trigger in this way:
Tab into the field -> Tab out -> Trigger validation

这怎么办?

推荐答案

此行为是设计使然.从文档

This behavior is by design. From the documentation

在将字段标记为无效之前,验证是懒惰的:在首次提交表单之前,用户可以在字段上进行制表,而不会收到烦人的消息-在有机会实际输入密码之前,他们不会被打扰.正确值 将字段标记为无效后,将立即对其进行验证:用户输入必要的值后,错误消息将被删除

Before a field is marked as invalid, the validation is lazy: Before submitting the form for the first time, the user can tab through fields without getting annoying messages – they won't get bugged before having the chance to actually enter a correct value Once a field is marked invalid, it is eagerly validated: As soon as the user has entered the necessary value, the error message is removed

这篇关于失去焦点时,MVC需要现场验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆