这是我从控制器返回的内容:
var states = _dc.States.ToList();
var serializer = new JavaScriptSerializer();
ViewBag.StateList = serializer.Serialize(states);
我的 JS:
var stateList = @Html.Raw(ViewBag.StateList);
var stateListModel = ko.mapping.fromJS(stateList);
是我做一个console.log
on stateListModel
,它总是[]
,但是stateList
是一个包含所有数据的完整数组。