[英]Ajax: Pass Model List to Controller
我有一個將模型列表作為模型的視圖,所以
@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),但都沒有用。
將contentType屬性設置為application / json。 並使用下面的代碼設置數據屬性
data: JSON.stringify({'your controllers parameter name': '@Model'})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.