嗨,当我尝试将 ContentType 放入按钮单击事件的 ajax 调用中时,我遇到了错误
viewmodel = ko.observableArray();
$(document).ready(function () {
$.ajax({
url: "/Render/LoadSurveyQuestions?sg=" + getUrlVars()["g"] + "&stg=" + getUrlVars()["sig"],
success: function (result) {
viewmodel = ko.mapping.fromJS(result);
ko.applyBindings(viewmodel, document.getElementById("tblQuestions"));
}
});
$("#btnNext").click(function () {
$.ajax({
type: 'post',
data: ko.toJSON(viewmodel),
url: "/Render/SaveSurveyQuestionOptions",
//contentType: "application/json; charset=utf-8",
// dataType: "json",
success: function (result) {}
});
});
我正在使用以下控制器方法来保存列表。使用 ajax 调用此方法时出现错误。
[System.Web.Http.HttpPost]
[JsonFilter(Param = "listobj", JsonDataType = typeof (List < SurveyQuestion > ))]
public void SaveSurveyQuestionOptions(List < SurveyQuestion > listobj) {
if (listobj.Count > 0) {
foreach(SurveyQuestion objSurveyQuestion in listobj) {
foreach(SurveyOption objOption in objSurveyQuestion.OptionList) {
//if (objOption.OptionSelected)
//{
// objSurveyQuestion.OptionId = objOption.OptionID;
// objSurveyQuestion.OptionText = objOption.OptionText;
//}
}
//osurveymanager.InsertQuestionAnswers(objSurveyQuestion);
}
}
}