在提交表单之前,我使用 Ajax 将数据发送到控制器 (InsertLead),然后我发布表单 ('SendForm()'),但缺少“表单数据”。
我正在用 chrome 进行测试:developers-tools
这是我的代码:
$(document).ready(function () {
var request;
$('#frm1').submit(function (e) {
event.preventDefault();
var referredUser = new ReferredUser();
referredUser.UserName = $("#fullname1").val();
referredUser.UserPhone = $("#mobilephone1").val();
referredUser.UserEmail = $("#email1").val();
referredUser.Country = $("#country1").val();
referredUser.ReferrerEmail = '@Model.ReferrerEmail';
if (referredUser.UserEmail.value == "") { return false; }
else {
$('#overlay').show()
if (request) {
request.abort();
}
// setup some local variables
var $form = $(this);
// select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
// serialize the data in the form
var serializedData = JSON.stringify(referredUser);
// disable the inputs for the duration of the ajax request
$inputs.prop("disabled", true);
// fire off the request to the form
request = $.ajax({
url: "/Forms/InsertLead",
type: "post",
data: serializedData,
contentType: 'application/json'
});
request.done(function (response, textStatus, jqXHR) {
$('#overlay').hide()
});
request.always(function () {
SendForm();
// re-enable the inputs
$inputs.prop("disabled", false);
});
}
});
});
function SendForm() {
var serial = '@Model.SerialId';
if (serial.val == "") {
serial = '-1';
}
var formURL = '@regFormURL';
$('#frm1').attr('action', formURL + '?SerialId=' + serial);
document.regForm1.submit();
}
表格:
<form name="regForm1" method="post" id="frm1" action="-1">
<input type="text" name="RegistrationModel.FullName" id="fullname1" />
<input type="text" name="RegistrationModel.Email" id="email1" />