作者:阿思翠 | 来源:互联网 | 2023-05-17 22:22
IwroteacustomvalidatorusingMVCDataAnnotationsandthejQueryunobtrusivejavascriptlibrary.
I wrote a custom validator using MVC DataAnnotations and the jQuery unobtrusive Javascript library. It's working great. The only problem I have now is that after the initial validation, if the user edit's the field, it's firing the validator on each keystroke. Since the validator hits a web service to validate the input, I'd prefer that it always just validate the input when the user moves off of the field or the form is submitted. Is there a way to change this behavior? Here's my code:
我使用MVC DataAnnotations和jQuery unobtrusive Javascript库编写了一个自定义验证器。它工作得很好。我现在唯一的问题是,在初始验证之后,如果用户编辑了该字段,它就会在每次击键时触发验证器。由于验证器访问Web服务以验证输入,我更倾向于在用户离开字段或提交表单时始终只验证输入。有没有办法改变这种行为?这是我的代码:
2 个解决方案