jquery验证不能与mvc一起使用

时间:2015-08-02 19:04:14

标签: jquery asp.net-mvc

我正在尝试向我的网页添加一个简单的jquery验证,但不会触发验证错误。 当我尝试与fiddler相同时,它正如预期的那样工作。 http://jsfiddle.net/qUYvS/381/

char[] first = ['2','3','.','4','5'];
char[] second = ['2','.','5'];

char[] result = CalculateSum(first,second);
Console.Write(result) --> Will print "25.95"
$("#form-wrap form").validate({
      rules: {
          Link: {
              required: true,
              url: true
          }
      },
      messages: {
          Link: {
              url: "Enter valid Url"
          }
      },
      submitHandler: function (form) {
          alert('valid form');
          form.submit();
      }
  });

这是渲染束的顺序

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
 <script type='text/javascript' src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
    
<div id="form-wrap">
<form action="#" method="post"><input name="__RequestVerificationToken" type="hidden" value="GL-DZaLE0C8unpgVgzCSNK4ltxZZTPjI_O-oM4K01GBrnePo31eqlAeBgDHIVk5XwmqABEJh6h077x9nXu5JyCU5nv_TKWXZHfbfiAH-tvCXh6_1cARsW2cOj11P-IwmP9RiSeAl9WyyOOKV7dMhYg2" />        <div class="form-horizontal">      
            <div class="form-group">
                <label class="control-label col-md-2" for="Link">Link</label>
                <div class="col-md-10">
                    <input class="form-control text-box single-line" id="Link" name="Link" type="text" value="" />
                    <span class="field-validation-valid text-danger" data-valmsg-for="Link" data-valmsg-replace="true"></span>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </div>
        </div>
</form></div>

我不确定为什么它在我的网页上不能用于提琴手。我在这里失踪的是什么?

3 个答案:

答案 0 :(得分:1)

T 他最好的方法,你可以在火狐中使用 火虫 插件,在Internet Explorer中调试或在windows中使用边缘浏览器10。

所以对于下载火灾错误click here

this link中,您可以看到文档页面。

答案 1 :(得分:0)

我终于弄清楚我错过了在标签下的_layout.cshtml中删除以下脚本渲染线。

==

当我删除它时它工作正常..

答案 2 :(得分:0)

如果你想自己编写有效规则,请不要参考jquery.validate.unobtrusive.js
它将在页面加载时添加自动验证 在jquey.validate js中,它将检查验证是否存在,如果为true,则不执行任何操作 如果你想添加更多规则,你可以使用$(...)。规则(&#34;添加&#34;,{...})
检查文档http://jqueryvalidation.org/rules
我之前回答了另一个问题,jQuery Unobtrusive client-side validation of custom attribute,你可以看到这个