2012-02-07 61 views
2

我真的很厌烦尝试使用Telerik在ASP.NET MVC上使用jQuery来验证表单。使用Telerik进行jQuery表单验证(ASP.NET MVC)

我试了一切.....我不明白我做错了什么。

我试过jQuery和jQuery验证器的最新版本,但它仍然不起作用。

$(document).ready(function() { 

    $("#customerForm").validate({ 

     rules: { 
     CustomerEnShortName:"required" 
    }, 
    messages: { 

     CustomerEnShortName: "<li>Please enter a name.</li>" 
    } 

}); 


}); 

The Telerik MVC code:

<% using (Html.BeginForm("Edit","Customer", FormMethod.Post, new{ id= "customerForm"})) { %> 
<%: Html.ValidationSummary() %> 
    <fieldset> 


<legend>CustomerInfo</legend> 

    <div class="editor-label"> 
     <label id="lblCustomerShortName">Customer Short Name</label> 
    </div> 
    <div class="editor-field"> 
     <%: Html.Telerik().AutoCompleteFor(m =>m.CustomerEnShortName) %> 
    </div> 

    <div class="editor-label"> 
     <label id="lblCustomerFullName" >Customer Full Name</label> 
    </div> 
    <div class="editor-field"> 
     <%: Html.Telerik().AutoCompleteFor(m => m.CustomerEnFullName) %> 
    </div> 



    <div class="editor-label"> 
       <label id="lblCustomerNIN">Customer NIN</label> 
    </div> 
    <div class="editor-field"> 
     <%:Html.Telerik().AutoCompleteFor(m => m.Customer_NIN) %> 
    </div> 





    <div class="editor-label"> 
     <%: Html.Label("Is Active") %> 
    </div> 

    <div class="editor-field"> 
    <% 
     string isActive; 
     if (Model.CustomerActivity == 1) 
      isActive = "true"; 
     else 
      isActive = "false"; 
      %> 
     <input id="IsActive" name="IsActive" type="checkbox" checked="<%= isActive %>" /> 
    </div> 

    <p> 
     <input type="submit" value="Save" /> 
    </p> 
</fieldset> 
<%} %> 

所生成的输出代码是:

<form action="/Customer/Edit/31" id="customerForm" method="post"> 
<div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li> 
    </ul></div> 
    <fieldset> 
      <legend>CustomerInfo</legend> 


     <div class="editor-label"> 
     <label id="lblCustomerShortName">Customer Short Name</label> 
    </div> 
    <div class="editor-field"> 
     <input class="t-widget t-autocomplete t-input" id="CustomerEnShortName" name="CustomerEnShortName" type="text" /> 
    </div> 

    <div class="editor-label"> 
     <label id="lblCustomerFullName" >Customer Full Name</label> 
    </div> 
    <div class="editor-field"> 
     <input class="t-widget t-autocomplete t-input" id="CustomerEnFullName" name="CustomerEnFullName" type="text" value="CUSTOMER -31" /> 
    </div>   

    <div class="editor-label"> 
       <label id="lblCustomerNIN">Customer NIN</label> 
    </div> 
    <div class="editor-field"> 
     <input class="t-widget t-autocomplete t-input" id="Customer_NIN" name="Customer_NIN" type="text" value="1559446285" /> 
    </div> 





    <div class="editor-label"> 
     <label for="Is_Active">Is Active</label> 
    </div> 

    <div class="editor-field"> 

     <input id="IsActive" name="IsActive" type="checkbox" checked="true" /> 
    </div> 

    <p> 
     <input type="submit" value="Save" /> 
    </p> 
</fieldset> 
</form> 

+0

如果您删除telerik控件,它是否工作? – gdoron 2012-02-07 13:21:23

回答

0

有在新版本中这将导致jquery.validate文件被包括在从ScriptRegistrar即使一个问题指定省略。

这可能导致您的验证失败。

尝试使用this hotfix来解决问题。