【发布时间】:2021-09-23 03:23:06
【问题描述】:
我在将 JSON 数据从 MVC 视图发送到控制器时遇到问题,我得到的只是控制器:
我在 Url.Action 中发送的 JSON 如下所示:(我自己通过 .push() 将数组添加到数组,然后通过 JSON.stringify 创建它)
[
[
{
"isOrdered":false,
"orderLineId":"4550",
"comment":"",
"orderId":"2789"
}
],
[
{
"isOrdered":false,
"orderLineId":"4551",
"comment":"",
"orderId":"2789"
}
]
]
我使用 JQuery ajax POST
$.ajax({
type: "POST",
url: "@Url.Action("SaveCheckboxesAndComments")",
data: JSON.stringify(array),
traditional: true,
contentType: "application/json; charset=utf-8",
dataType: 'json'
});
和我的控制器:
public class JsonData
{
public bool IsOrdered { get; set; }
public string OrderLineId { get; set; }
public string Comment { get; set; }
public int OrderId { get; set; }
}
[HttpPost]
public async Task<ActionResult> SaveCheckboxesAndComments(List<JsonData> jsonArray)
{...
我应该更改我的类 JsonData 或 JS 中的某些内容以获取值吗?因为不知何故“框架”在起作用。
【问题讨论】:
标签: javascript jquery json asp.net-mvc model-view-controller