以下JavaScript代码调用ASP.NET控制器操作,并且应该使用返回的PartialView填充元素。相反,它会在浏览器控制台“TypeError:undefined没有属性”中抛出错误。这显然很模糊,我不确定如何前进。在调试时,我看到它将运行到AJAX调用的成功/失败部分,传递成功/失败,再次尝试AJAX调用,然后抛出错误。
$(".form-module").on("submit", function (event) {
event.preventDefault();
var thisForm = $(this);
if (formIsSetupProperly(thisForm) === false) {
return;
}
var formSubmitButton = Ladda.create(thisForm.find(".form-module-submit-button")[0]);
formSubmitButton.toggle();
var controller = $(this).data("controller");
var action = thisForm.data("action");
var method = thisForm.data("method");
var serializedForm = thisForm.serialize();
$(this).validate();
$.ajax({
type: method,
cache: false,
data: serializedForm,
url: "/" + controller + "/" + action,
success: function (data) {
if (data.isError === true) {
console.error(data.message.Text);
$(".clear-on-error").val("");
thisForm.addClass("has-error");
thisForm.find(".form-module-error").html(data.message.Text);
formSubmitButton.toggle();
} else if (data.isRedirect === true) {
window.location = data.message.Url;
formSubmitButton.toggle();
} else {
thisForm.closest("#wizard").html(data).promise().done(function () {
var thisFormCallback = thisForm.data("callback");
if (thisFormCallback !== undefined) {
eval(thisFormCallback + "()");
}
});
ajax_loader_init();
}
},
fail: function (error) {
console.error(error);
formSubmitButton.toggle();
}
});
});