我有一个关于在JavaScript中使用列表发布模型的问题。
我似乎无法在控制器中的列表中获取变量。我只得到普通变量和列表中的行数。
我的控制器:
OperatorSchoolSums finalResult = new OperatorSchoolSums{ posSums = new List<SchoolPOSSums>()};
foreach (var listVar in goodlist)
{
finalResult.classAList.Add(listVar);
}
return View(finalResult);
}
“ VIEW”窗口中的JavaScript。
<script type="text/javascript">
function SaveCheckInfos() {
var ListModel = [];
for (var r = 0, n = Tables.length; r < n; r++) {
var ListMod = {
Sum1: 0,
Sum2: 0,
Sum3: 0,
Sum4: 0
};
for (var c = 0, m = foundTables[i].rows[r].cells.length; c < m; c++) {
ListMod.Sum1 = ....;
ListMod.Sum2 = ....;
ListMod.Sum3 = ....;
ListMod.Sum4 = ....;
ListModel.push(ListMod);
}
}
}
var cid = $("#dailyCheckID").val();
var checkObj = {
"dailyCheckID": cid,
"posSums": ListModel
};
debugger
$('#DivToAppendPartialVoew').dialog('close');
var jsonAsk =
$.post('../Controller/ConfirmDailyCheck', checkObj,
function(data) {
if (data == null) {
alert('Error happened');
} else {
alert(data.name);
}
}, 'json'
);
jsonAsk.fail(function() {
alert("error");
});
}
$(document).ajaxError(function(event, request, settings, thrownError) {
alert("ERROR" + thrownError);
$("#msg").append("<li>Error requesting page " + settings.url + "</li>");
});
</script>
我可以在浏览器调试器中看到最终模型。就像这样:
开机自检
[HttpPost]
public ActionResult ConfirmDailyCheck(OperatorSchoolSums model)
{
//do something here
return Json("answer", JsonRequestBehavior.AllowGet);
}