CAl*_*lex 2 asp.net-web-api asp.net-core angular angular-httpclient
我有一个带有这个 Put 请求方法的 Angular 服务:
put(peopleFieldID: number, peopleFieldName: string): Observable<number> {
let params = new HttpParams();
params = params.append("peopleFieldID", peopleFieldID.toString());
params = params.append("peopleFieldName", peopleFieldName);
return this.http
.put<number>(this.url, { params: params })
.pipe(catchError(this._errorHandling.handleError.bind(this)));}
Run Code Online (Sandbox Code Playgroud)
以上在我的 .net 核心 API 上命中了这个端点:
[Authorize(Roles = "Client")]
[Route("")]
[HttpPut]
public IActionResult C_Update(int peopleFieldID, string peopleFieldName )
{
//Make call to the proper repo method.
return Json(_peopleFieldRepo.C_Update(peopleFieldID, peopleFieldName));
}
Run Code Online (Sandbox Code Playgroud)
peopleFieldID 和 peopleFieldName 这两个参数始终为 0 和 null。我已经指出 Angular 前端正确发送了参数,但后端无法识别它们。我有许多其他端点可以正常工作。
如果您没有,则需要使用HttpParams和传递null有效载荷来设置查询参数:
const params = new HttpParams()
.set('peopleFieldID', peopleFieldID.toString())
.set('peopleFieldName', peopleFieldName);
// if you have a payload to pass you can do that in place of null below
return this.http
.put<number>(this.url, null, { params: params })
.pipe(catchError(this._errorHandling.handleError.bind(this)));}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2909 次 |
| 最近记录: |