使用Telerik进行jQuery表单验证(ASP.NET MVC)

时间:2012-02-07 13:01:37

标签: jquery asp.net-mvc-3 telerik-mvc

我真的厌倦了尝试使用Telerik在ASP.NET MVC上使用jQuery验证表单。

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

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

$(document).ready(function () {

    $("#customerForm").validate({

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

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

});


});

The Telerik MVC code:

$(document).ready(function () { $("#customerForm").validate({ rules: { CustomerEnShortName:"required" }, messages: { CustomerEnShortName: "<li>Please enter a name.</li>" } }); });

 

生成的输出代码为:

<% 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>
<%} %>

1 个答案:

答案 0 :(得分:0)

新版本中存在一个问题,即使指定要省略,也会导致从ScriptRegistrar中包含jquery.validate文件。

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

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