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

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

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

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

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

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

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

最佳答案

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

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

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

关于使用 Telerik (ASP.NET MVC) 进行 jQuery 表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9176715/

相关文章:

c# - 将 Jquery 数据表中的所有数据从 View 绑定(bind)到 Controller

jquery - jquery 计算类之前的项目数

asp.net - 在 MVC 3 中的 url 中传递多个参数

asp.net - Application_MapRequestHandler 有时真的很慢

javascript - 将 'active' 类添加到主选项卡列表中

ASP.NET MVC 3 和来自多个来源的身份验证支持

asp.net-mvc - Telerik 远程虚拟化 (Kendo Grid)

c# - Telerik MVC Extensions Grid - 如何将网格过滤器应用于初始 LINQ 查询或传递到数据库?

kendo-ui - 如何安排 Kendo Scheduler 的周末

Javascript Regex 或 Jquery 解析 html 字符串?