$("#CreateDepartmentForm").submit(function (e) { e.preventDefault();
var modelx = $(this).serialize();
console.log(modelx);
var cars = [
{
"color": "purple",
"type": "minivan",
"registration": "2018-03-03",
"capacity": 7
},
{
"color": "red",
"type": "station wagon",
"registration": "2018-03-03",
"capacity": 20
}];
$.ajax({
type: "POST",
url: "/Department/CreateDepartmentByAjax",
data: modelx "&test=" cars,
success: function (res) {
},
});
public IActionResult CreateDepartmentByAjax(DepartmentVM model,List<cars> test)
{
}
public class cars
{
public string color { get; set; }
public string type { get; set; }
public string registration { get; set; }
public int capacity { get; set; }
}

Visual Studio 除錯輸出

uj5u.com熱心網友回復:
如果要為 POST 請求傳遞類似查詢引數的陣列,則需要在控制器方法中將 [FromQuery] 屬性添加到串列引數。相反,最好將 json 有效負載放在請求正文中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/430385.html
標籤:C# 阿贾克斯 asp.net-mvc asp.net 核心 asp.net-ajax
