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; }
}
|