我使用的是asp.net Core web API &角。"代码"&正确显示'pageInfo'值在控制台,但是当传递给API时,字符串正确传递只有对象显示错误值(0和null)。
API——
[HttpPost("get/{code}/{pageInfo}")]
public IActionResult Get(string code, Model pageInfo)
{
var data = _Service.GetData(code, pageInfo);
if (data != null)
{
---
}
else
{
---
}
}
服务——
getAllData(code:any,pageInfo:any):Observable<any>{
console.log(code, pageInfo);
const url = `/get/${code}/${pageInfo}`;
return this.http.post<any>(url, code, pageInfo);
}
谁能帮我找出我在这里犯了什么错误?我已经通过一些修改解决了我的问题-
- 改变参数顺序 使用[FromBody]
API——
[HttpPost("get/{code}/{pageInfo}")]
public IActionResult Get([FromBody] Model pageInfo, string code)
{
var data = _Service.GetData(pageInfo, code);
if (data != null)
{---}
else
{---}
}
服务——
getAllData(pageInfo:any, code:any):Observable<any>{
const url = `/get/${code}`; // have passed only the string value via URL
return this.http.post<any>(url, pageInfo, code);
}