【问题标题】:jQuery remote validation not working on keypress, only working on focus changejQuery远程验证不适用于按键,仅适用于焦点更改
【发布时间】:2012-04-09 09:50:37
【问题描述】:

我有一个视图模型

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 asp.net-mvc jquery-validate remote-validation


    【解决方案1】:

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

    这样你就可以了

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

    【讨论】:

    • 感谢这工作。但很想知道问题的根本原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多