我试图在表单提交时使用AjaxOptions运行两个函数。但是,只调用了一个函数。我希望在提交表单时运行它们。
这是我的ajax选项:
@using (Ajax.BeginForm("AddDiagnosis", "Student",
new AjaxOptions(){
OnSuccess = "HandleAddDiagnosisCode",
OnBegin = "return ValidateAddStudentDiagnosisCode(" + @studentId + ")"
}, 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();
});
}
提交表单时不会调用我的测试提醒。
答案 0 :(得分:0)
您可以使用以下匿名函数包装函数调用:
@using (@Ajax.BeginForm("AddDiagnosis", "Student", new AjaxOptions
{
OnSuccess = "new function(){func1(xhr); func2();}"
})