用于验证和绑定表单信息的Ajax选项

时间:2017-12-08 17:51:49

标签: javascript html twitter-bootstrap

我的应用程序中的表单已发布到数据库中,然后在提交时显示在数据表中。

我正在使用Ajax.begin表单来运行我的JS函数。但是,我只能运行第一个函数。我希望能够运行这两个函数并发布信息。

以下是我的HTML中的beginForm:

 @using (Ajax.BeginForm("AddDiagnosis", "Student",
            new AjaxOptions(){              
                OnBegin = "return ValidateAddStudentDiagnosisCode(" + @studentId + ")",
                OnSuccess = "HandleAddDiagnosisCode"               

            }, new
            {
                id = "AddStudentDiagnosis-" + @studentId,
                name = "AddStudentDiagnosis-" + @studentId
            }
            ))
        {

功能:

function ValidateAddStudentDiagnosisCode(id) {   
    var valid = true;    
    var msg = "";
    var errorPanel = $('#modal-AddStudentDiagnosis-ErrorPanel');
    PopulateErrorMessage(errorPanel, msg);
    errorPanel.hide();
    var diagCode = $('#modal-AddStudentDiagnosis_DiagCode-' + id).val();

    if (diagCode === "") {
        msg = "You must select a diagnosis code";
        valid = false;
    }
    var sequence = $('#modal-AddStudentDiagnosis_Sequence-' + id).val();
    if (sequence === "") {
        msg = "You must select a sequence";
        valid = false;        
    }
    if (valid == false) {
        PopulateErrorMessage(errorPanel, msg);      
    }    
    return valid;
}

function HandleAddDiagnosisCode(e) {

    alert('test');
    var errorPanel = $('#modal-AddStudentDiagnosis-ErrorPanel');
    PopulateErrorMessage(errorPanel, '');
    var errorMessage = e.errorMessage;
    if (errorMessage.length > 0) {
        PopulateErrorPanel(errorPanel, errorMessage);
    }
    else {
        ClearModal();        
        // Reload the document view
        $('#detailPanel').fadeOut(500, function () {
            $(this).empty();
        }).fadeIn(250, function () {
            $(this).html(e.Html);
            BindDocumentEdit();
            BindDataTable();
            BindDatePickers();            
        });
    }
}

如上所述,只有ValidateAddStudentDiagnosisCode正在运行。

0 个答案:

没有答案