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()
});
谢谢,这很有效。但我很想知道问题的根本原因。