【发布时间】:2020-01-09 13:06:37
【问题描述】:
我有一个将模型列表作为模型的视图,所以
@model List<Collections.Models.Status>
我想将此列表作为 Ajax 调用的数据传递,但我不断得到“System.Collections.Generic.List[Collections.Models.Status]”而不是模型中的值。
这是 Ajax 代码:
$.ajax({
url: "/Home/Update",
data: JSON.stringify(@Model),
type: 'POST',
dataType: 'json',
success: function (responseJSON) {
if (responseJSON.message == 'success') {
alert('here');
}
},
error: function (error) {
showModal("Error: " + error.message);
}
});
在调试器中翻译为:
$.ajax({
url: "/Home/Update",
data: JSON.stringify(System.Collections.Generic.List`1[Collections.Models.CollectionStatus]),
type: 'POST',
dataType: 'json',
success: function (responseJSON) {
if (responseJSON.message == 'success') {
alert('here');
}
},
error: function (error) {
showModal("Error: " + error.message);
}
});
如何传递列表的实际值而不是 System.Collections.Generic.List[Collections.Models.Status]?
我试过@Model.ToList()、@Html.Raw(Model),都没有成功。
【问题讨论】:
标签: javascript ajax model-view-controller model