【问题标题】:jQuery form validation using Telerik (ASP.NET MVC)使用 Telerik (ASP.NET MVC) 的 jQuery 表单验证
【发布时间】:2012-02-28 21:47:34
【问题描述】:

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

我什么都试过了......我不明白我做错了什么。

我尝试了最新版本的 jQuery 和 jQuery 验证器,但仍然无法正常工作。

$(document).ready(function () {

    $("#customerForm").validate({

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

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

});


});

Telerik MVC 代码:

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

【问题讨论】:

  • 如果你去掉 Telerik 控件,它会起作用吗?

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


【解决方案1】:

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

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

尝试使用this hotfix 解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-29
    相关资源
    最近更新 更多