2012-04-09 64 views
0

我有一個視圖模型jQuery的遠程驗證,唯一的工作焦點變化

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 = "[email protected]"; 
      return View(userRegister); 
     } 

遠程驗證適用於在電子郵件沒有預填表格按鍵事件,但是當電子郵件字段預填充(上面的代碼),該遠程驗證(按鍵事件)不起作用。這隻在焦點改變時才起作用。

有什麼建議嗎?

回答

0

我不知道這個問題,但你可以通過做"$("FormSelector").valid()

使用jQuery來驗證從這樣你就可以做

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

由於這個工作。但很想知道問題的根源。 – HashCoder 2012-04-10 08:59:56