如果作为正常的formpost(页面重定向)发送,则表单似乎已成功发布。
但是如果通过jquery serialize或FormData对象发送它,它会发送一个空对象..
示例表单和ajax调用如下:
<form role="form" action="@Url.Action("InsertUpdateQuestion", "TemplateBuilder")" method="post" id="questionTempDetailsForm" >
<div class="form-group">
<div class="row">
<div class="col-xs-4">
<label class="control-label small" for="ShortName">Short Name<span class="required">*</span></label>
<input class="form-control" id="ShortName" name="ShortName" type="text">
</div>
<div class="col-xs-4">
<label class="control-label small" for="questionType">Type<span class="required">*</span></label>
@Html.DropDownList("QuestionTypeId", (List<SelectListItem>)ViewBag.QuestionType, "-- Select --",
new { @id = "questionType", @name = "questionType", @class = "chosen-select form-control", onchange = @"QuestionTypeChanged(this.value);" })
<input id="questionTypeName" name="questionTypeName" type="text" hidden="hidden">
</div>
<div class="col-xs-2 pad-a-labelsize">
<div class="checkbox-custom checkbox-default">
<input id="chkNewLine" style="margin-top: 20px;" name="chkNewLine" type="checkbox">
<h5 class="modal-title small">New Line</h5>
</div>
</div>
<div class="col-xs-2 pad-a-labelsize-btn">
<button id="btnQuestionSave" style="margin-top: 23px;" class="btn btn-primary btn-sm rightbtn " type="button" onclick="SubmitQuestionData();"> Save</button>
</div>
<div class="col-xs-12">
<label class="control-label small" for="questionName">Question<span class="required">*</span></label>
<input class="form-control" id="questionName" name="questionName" type="text" placeholder="Your Question" onblur="getText();">
</div>
</div>
</div>
</form>
ajax电话:
function SubmitQuestionData() {
debugger;
//return true;
var myform = document.getElementById("questionTempDetailsForm");
var fd = new FormData(myform);
var url = $("#questionTempDetailsForm").attr("action");
$.ajax({
url: url,
type: "post",
data: fd,
dataType: "json",
async: false,
traditional: true,
processData: false,
success: function (msg) {
ShowAlertMessage(msg.ResponseText, msg.MessageClass);
if (msg.RedirectUrl != null && msg.RedirectUrl.length > 0) {
setTimeout(LoadPage, 1500, msg.RedirectUrl, "User");
}
},
error: function (res) {
ShowAlertMessage("an error occured..", "User");
}
});
return false;
}
任何帮助高度赞赏..