信息发布→ 登录 注册 退出

Vue与.net Core 接收List<T>泛型参数

发布时间:2026-01-11

点击量:
目录
  • 1、不能接收到的情况
  • 2、 能接收到的情况
  • Vue Element-ui axios-post请求,axios默认请求提的Content-Type为application/json
  • .net core后端接收参数有List<T>泛型参数,如何才能正确接收呢

1、不能接收到的情况

  • 前端参数值
/*请求参数值*/
var data=[]
data.push({
  id:1,
  name:'aaa'
})
data.push({
  id:2,
  name:'bbb'
})
data.push({
  id:3,
  name:'ccc'
})
  •  后端代码
[HttpPost]
public JsonResult Data(List<entity> list)
{
    return Json(new { c = 200, m = "test" });
}
public class entity
{
    public int id { get; set; }
    public string name { get; set; }
}

2、 能接收到的情况

  • 前端参数值
/*请求参数值*/
var data={
    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<model> list { get; set; }
}
public class model
{
    public int id { get; set; }
    public string name { get; set; }
}
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!