我无法在使用ajax的部分视图上以模态提交表单,因为我得到了不确定的unobtrusive,这意味着jquery unobtrusive引用无法正常工作
@model HutLogistica.ViewModels.LoginViewModel
@{
Layout = null
}]
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/login.css" rel="stylesheet" />
<link href="~/Content/fontawesome-all.css" />
<script src="~/scripts/jquery-3.3.1.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/fontawesome/all.js"></script>
这是我局部视图的顶部
但是我得到未定义的form.valid()
<script type="text/javascript">
$(document).ajaxStart(function () {
$("#formModal").hide();
$("#loader").removeClass('d-none');
});
$(document).ajaxStop(function () {
$("#loader").addClass('d-none');
});
$(function () {
$("#formModal").submit(function () {
var form = $('#formModal');
var formData = form.serialize();
if (form.valid()) {
event.preventDefault();
$.ajax({
url: this.action,
type: this.method,
cache: false,
data: formData,
success: function (response) {
debugger
if (response.success) {
alert('Autenticado com sucesso');
$('#loginModal').modal('hide');
//Refresh
location.reload();
} else {
alert(response.responseText);
}
},
error: function (response) {
alert(response.responseText)
}
});
}
});
});
</script>
虽然jquery和fontawesome似乎正常工作,但jquery无法验证?