2010-05-19 50 views
2

我使用jQuery驗證插件和遠程屬性與emailId一起使用,但不與mobileNo?爲什麼jQuery驗證插件的遠程屬性對我無效?

var validator = $("#addform").validate({ 
    rules: { 
    Name: "required", 
    MobileNo: { 
      required: true, 
      minlength: 10, remote: '<%=Url.Action("getClientMobNo", "Clients") %>' 
       }, 
       Address: "required" 
       }, 
    messages: { 
     Name: "please provide a client name", 
     MobileNo: { 
      required: "Please provide a mobile phone no", 
      rangelength: jQuery.format("Enter at least {0} characters"), 
      remote: jQuery.format("This MobileNo is already in use") 
     }, 
     Address: "please provide client address" 
     }, 

一個null值傳遞給我的控制器行動。任何建議...

public JsonResult getClientMobNo(string mobno) 
    { 
     JsonResult result = new JsonResult(); 
     string status = clirep.getClientMobNo(Convert.ToInt64(mobno)); 
     if (status == "Mobile No already exists") 
     { 
      result.Data = false; 
     } 
     else 
     { 
      result.Data = true; 
     } 
     return result; 
    } 

回答

0

變量名稱不匹配起來。 JQuery傳遞一個MobileNo的參數,但是你的函數正在尋找mobno。改變你的功能接受參數MobileNo,你會得到你的價值。

public JsonResult getClientMobNo(string MobileNo) 
{