Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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
Javascript jquery.valid()=远程验证前为true_Javascript_Jquery_Validation_Asp.net Mvc 5_Remote Validation - Fatal编程技术网

Javascript jquery.valid()=远程验证前为true

Javascript jquery.valid()=远程验证前为true,javascript,jquery,validation,asp.net-mvc-5,remote-validation,Javascript,Jquery,Validation,Asp.net Mvc 5,Remote Validation,我在MVC5中工作,并结合使用客户端和服务器验证。对于这个特殊问题,我使用远程验证 Razorview: <div id="studentStatus" name="studentStatus"> @using (Html.BeginForm("StudentStatus", "StudentStatus", FormMethod.Post, new { id = "studentStatusForm", data_timer = 240000 })) { @Html.Hid

我在
MVC5
中工作,并结合使用客户端和服务器验证。对于这个特殊问题,我使用远程验证

Razorview

<div id="studentStatus" name="studentStatus">
@using (Html.BeginForm("StudentStatus", "StudentStatus", FormMethod.Post, new { id = "studentStatusForm", data_timer = 240000 }))
{
    @Html.HiddenFor(x => x.CurrentStudentSepId, new { @class = "hideMe" })
    <div class="row">
        <h2 class="col-md-12 topSectionHeader">
            @StaffPortalResources.Section_StudentStatus
            <span class="savedStatus"></span>
        </h2>
    </div>
    <span class="errorNotification"></span>
    <div class="questionGroup form-group">
        <div class="row margin-btm-sm">
            <div class="col-md-4">
                @Html.LabelFor(x => x.StudentStatusId)
                @if (Model.IsReadOnly)
                {
                    <div>@Html.DisplayFor(x => x.StudentStatusId)</div>
                    @Html.HiddenFor(x => x.StudentStatusId)
                }
                else
                {
                    @Html.CustomComboBoxFor(x => x.StudentStatusId, (new { @class = "statusChangeValidationHandler", data_action = "GetStudentEditableStatuses", data_controller = "Lookup" }))
                }

                @Html.ValidationMessageFor(x => x.StudentStatusId)
            </div>
 }
控制员:

public JsonResult ValidateStudentStatus(StudentStatusSectionViewModel model)
{
    var errors = _studentStatusSectionAdapter.ValidateStudentStatus(model.CurrentStudentSepId, model.StudentStatusId);
    if (errors != null && errors.Any())
    {
        var currentStatus = _studentStatusSectionAdapter.Get(model.CurrentStudentSepId).StudentStatusId;
        Response.AddHeader("status", currentStatus);
        return Json(string.Join("</br>", errors), JsonRequestBehavior.AllowGet);
    }

    return Json(true, JsonRequestBehavior.AllowGet);
}
用于连接更改事件验证的jquery:

scope.initializeAutoSave = function (form, callBack) {
    var $form = $(form);
    $form.on("change", "input:not(.ignoreAutoSave)", queueForm);
    $form.on("change", "textarea:not(.ignoreAutoSave)", queueForm);
    window.Validation.initializeValidator($form);
    callBacks[$form.attr('id')] = callBack || function() {};
}
queueForm方法:

function queueForm(e) {
    if ($(e.target).valid()) {
        var $form = $(e.target).closest("form");
        var timer = $form.data("timer");
        autoSaveQueue[$form.attr("id")] = { $form: $form, timer: timer, attempt: 0 };
    }
}
在更改下拉列表中的值后跟踪代码时,change事件激发并调用queueForm函数。
valid()
调用在远程验证发生之前计算为true

直到我跳过“if
($(e.target).valid())
”行,它的计算结果为true并进入if块。然后跳入控制器中的远程
ValidateStudentStatus
功能

我做错什么了吗?我是否误解了远程验证的工作原理

如有任何见解或帮助,将不胜感激

scope.initializeAutoSave = function (form, callBack) {
    var $form = $(form);
    $form.on("change", "input:not(.ignoreAutoSave)", queueForm);
    $form.on("change", "textarea:not(.ignoreAutoSave)", queueForm);
    window.Validation.initializeValidator($form);
    callBacks[$form.attr('id')] = callBack || function() {};
}
function queueForm(e) {
    if ($(e.target).valid()) {
        var $form = $(e.target).closest("form");
        var timer = $form.data("timer");
        autoSaveQueue[$form.attr("id")] = { $form: $form, timer: timer, attempt: 0 };
    }
}