Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery远程验证不适用于按键,只适用于焦点更改_Jquery_Asp.net Mvc_Jquery Validate_Remote Validation - Fatal编程技术网

jQuery远程验证不适用于按键,只适用于焦点更改

jQuery远程验证不适用于按键,只适用于焦点更改,jquery,asp.net-mvc,jquery-validate,remote-validation,Jquery,Asp.net Mvc,Jquery Validate,Remote Validation,我有一个视图模型 public class UserRegister { [Remote("CheckUserEmail")] public string Email { get; set; } } 有一个寄存器视图,它是使用UserRegister模型强类型的 @Html.EditorFor(model => model.Email) 在用户控制器中,我有操作寄存器 public ActionResult Register()

我有一个视图模型

public class UserRegister
    {
        [Remote("CheckUserEmail")]
        public string Email { get; set; }
    }
有一个寄存器视图,它是使用UserRegister模型强类型的

@Html.EditorFor(model => model.Email)
在用户控制器中,我有操作寄存器

 public ActionResult Register()
        {
            UserRegister userRegister = new UserRegister();
            //// remote validation does not work on key press when the email field is not empty, 
            //// if i comment the below line or set the email as empty then remote validation works on keypress
            userRegister.Email = "abc@abc.com";
            return View(userRegister);
        }
远程验证在未预填充电子邮件的表单中对按键事件起作用,但在预填充电子邮件字段(上述代码)时,远程验证(对按键事件)不起作用。这仅在焦点改变时才起作用


有什么建议吗?

我不知道这个问题,但是您可以使用jquery通过执行
“$(“FormSelector”).valid()来验证from

所以你可以

$("input[type='text'"]).keypress(function() {
  $(this).valid()
    //Or if you want to validate the whole form
  $(this).closest('form').valid()
});

谢谢,这很有效。但我很想知道问题的根本原因。