一、传数组
js:
return request({
url: '',
method: 'post',
data:[1,2,3]
})
服务端写法:
[HttpPost]
public Response 方法名([FromBody] string[] ids) {}//ids的名称自定义
二、传一个对象集合(传单个对象的方法与之相同)
如实体类叫 student:
class student{
name{get;set;}
age{get;set;}
}
js:
return request({
url: '',
dataType: "json",
contentType: "application/json;charset=utf-8",
method: 'post',
data:rows //rows是一个数组,里面是json对象,如:[{name:"a",age:1},{name:"b",age:2}]
})
服务端方法:
[HttpPost]
public Response 方法名([FromBody] List<student> rows){}//其中rows是形参名,自定义
三、同时传集合和其他参数
//js:
return request({
url: '',
dataType: "json",
contentType: "application/json;charset=utf-8",
method: 'post',
params: { a:"123" },
data:rows//rows是一个数组,里面是json对象,如:[{name:"a",age:1},{name:"b",age:2}]
})
//服务端
[HttpPost]
public Response 方法名([FromBody] List<student> rows, [FromQuery] string a)