Asp.Net|【小5聊】Vue与.net Core 如何接收List<T>泛型参数

【Asp.Net|【小5聊】Vue与.net Core 如何接收List<T>泛型参数】Vue Element-ui axios-post请求,axios默认请求提的Content-Type为application/json
.net core后端接收参数有List泛型参数,如何才能正确接收呢
1、不能接收到的情况
  • 前端参数值
/*请求参数值*/ var data=https://www.it610.com/article/[] data.push({ id:1, name:'aaa' }) data.push({ id:2, name:'bbb' }) data.push({ id:3, name:'ccc' })

  • 后端代码
[HttpPost] public JsonResult Data(List list) { return Json(new { c = 200, m = "test" }); }public class entity { public int id { get; set; } public string name { get; set; } }

2、 能接收到的情况
  • 前端参数值
/*请求参数值*/ var data=https://www.it610.com/article/{ length:0, list:[] }var list=[] list.push({ id:1, name:'aaa' }) list.push({ id:2, name:'bbb' }) list.push({ id:3, name:'ccc' })data.length=list.lenght data.list=list

  • 后端代码
[HttpPost] public JsonResult Data(entity entity) { return Json(new { c = 200, m = "test" }); }public class entity { public int length { get; set; } public List list { get; set; } }public class model { public int id { get; set; } public string name { get; set; } }

    推荐阅读