Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc JQueryValidation与MVC 4不在模糊上验证_Asp.net Mvc_Jquery Validation Engine - Fatal编程技术网

Asp.net mvc JQueryValidation与MVC 4不在模糊上验证

Asp.net mvc JQueryValidation与MVC 4不在模糊上验证,asp.net-mvc,jquery-validation-engine,Asp.net Mvc,Jquery Validation Engine,我用MVC4和jQuery验证在墙上敲了几个小时的头,以验证blur上的第一个。我已经尝试将验证附加到整个表单和单个元素(第一个字段)上,但没有成功。如果我在blur事件中添加alert(),它似乎会触发,但不会验证所需字段。我有额外的验证添加后,需要的是工作,但还没有得到他们。我不知道MVC4有什么问题。JQueryvalidate是v1.10。我还尝试设置验证器,然后使用.blur对我想要验证的元素调用.valid() $(function () { $('#productionOr

我用MVC4和jQuery验证在墙上敲了几个小时的头,以验证blur上的第一个。我已经尝试将验证附加到整个表单和单个元素(第一个字段)上,但没有成功。如果我在blur事件中添加alert(),它似乎会触发,但不会验证所需字段。我有额外的验证添加后,需要的是工作,但还没有得到他们。我不知道MVC4有什么问题。JQueryvalidate是v1.10。我还尝试设置验证器,然后使用.blur对我想要验证的元素调用.valid()

$(function () {
    $('#productionOrder').focus();

    $.validator.addMethod("cMinLength", $.validator.methods.minlength,
        $.format("Must contain as least {0} chars"));
    $.validator.addClassRules("productionOrder", { cMnLength: 3 });

    $('#myForm').validate({
        onkeyup: false,
        //onfocusout: false,
        errorClass: 'fieldError'
        //rules: {
        //    productionOrder: "required number",
        //    tc: "required",
        //    dn: "required"
        //}
    });

    $("#towCount").bind("change keyup", function () {
        $form.validate().element("#towCount");
    });

    //$('#productionOrder').validate({
    //    //onkeyup: false,
    //    onfocusout: false,
    //    errorClass: 'fieldError',
    //    rules: {
    //        productionOrder: { 
    //            required: true 
    //        }
    //    }
    //});
});
还有.cshtml

@model FiberLine2.ViewModels.Creel
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Test</title>
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <style>
        .fieldError {
            border-color: red;
            border-width: medium;
        }

        .input-label {
            font-size: 13px;
            width: 130px;
            height: 30px;
            display: inline-block;
        }
    </style>
</head>
<body>
    <form id="myForm">
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <div>
            <!-- app header -->
            <label>@Resources.Strings.User: </label>
            <label>@User.Identity.Name</label>
        </div>
        <fieldset>
            <legend>@Resources.Strings.Creel @Resources.Strings.Load</legend>
            <div>
                <div id="errorDiv"></div>
                <hr />
                @Html.Label(@Resources.Strings.ProductionOrder, new { @class = "input-label lock" })
                <input type="text" id="productionOrder" name="productionOrder" class="required" maxlength="4" />
                <br />
                <label class="input-label lock">@Resources.Strings.Tow  @Resources.Strings.Count</label>
                <input type="text" id="towCount" name="tc" class="required" size="5" maxlength="5" value="299" />
                <br />
                <label class="input-label lock">@Resources.Strings.Batch @Resources.Strings.Sequence</label>
                <input type="text" id="doffNumber" name="dn" size="5" maxlength="5" value="1" />
                <br />
                <label class="input-label">@Resources.Strings.Creel @Resources.Strings.Position</label>
                <input type="text" id="creelPosition" name="cp" size="5" maxlength="5" />
                <br />
                <label class="input-label">@Resources.Strings.Batch @Resources.Strings.ID</label>
                <input type="text" id="creelNumber" name="cn" size="7" maxlength="7" />
                <br />
                <hr />
            </div>
            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>
    </form>
</body>
</html>
@model FiberLine2.ViewModels.Creel
@{
布局=空;
}
试验
.字段错误{
边框颜色:红色;
边框宽度:中等;
}
.输入标签{
字体大小:13px;
宽度:130px;
高度:30px;
显示:内联块;
}
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Resources.Strings.User:
@User.Identity.Name
@Resources.Strings.Creel@Resources.Strings.Load

@Html.Label(@Resources.Strings.ProductionOrder,新的{@class=“input Label lock”})
@Resources.Strings.Tow@Resources.Strings.Count
@Resources.Strings.Batch@Resources.Strings.Sequence
@Resources.Strings.Creel@Resources.Strings.Position
@Resources.Strings.Batch@Resources.Strings.ID


你能试试这个吗

var settngs = $.data($('#myForm')[0], 'validator').settings;
settngs.onkeyup = false;