我正在尝试使用淘汰模板绑定来绑定问题列表。我成功获取数据和模板绑定。但是在下一个按钮单击事件上,我试图将视图模型发送到控制器,但它在控制器中给出了空值
我的jquery代码是这样的
$(document).ready(function () {
$.ajax({
type: "GET",
contentType: "application/json",
url: "/Render/LoadSurveyQuestions?sg=" + getUrlVars()["g"] + "&stg=" + getUrlVars()["sig"],
success: function (result) {
var lstQns = JSON.parse(result);
viewmodel = ko.mapping.fromJS(lstQns);
ko.applyBindings(viewmodel, document.getElementById("tblQuestions"));
}
});
$("#btnNext").click(function () {
$.ajax({
async: true,
cache: false,
type: 'post',
url: "/Render/SaveSurveyQuestionOptions",
data: ko.toJSON(viewmodel),
success: function (result) {
}
});
});
});
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
vars[key] = value;
});
return vars;
}
控制器是这样的
[HttpPost]
public void SaveSurveyQuestionOptions(List<Question> listOfQuestions)
{
if (listOfQuestions.Count > 0)
{
Question objQuestion = new Question();
osurveymanager.InsertQuestionAnswers(objQuestion);
}
}
Here i am getting listOfQuestions as null value
请帮助我提前谢谢