.net - 通过 Angular 传递的 Web Api 参数为空
问题描述
因此,我试图通过 Angular 服务中的 put 调用将字符串传递给我的 Web Api。服务实际上是调用Web Api端的方法,但是参数总是通过null来的。有人能解释一下吗,谢谢。
代码如下所示:
Web Api:(断点设置在第一个括号上)
public void Put([FromBody]string userId)
{
}
角度:
UpdateManagerEmail(userId){
userId = '577f1e6e-146d-49f1-a354-b31349e7cb49';
const headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
this._http.put('http://localhost:428/api/User', {
userId : userId
}).subscribe(returnVal => {
console.log('returned');
});
}
解决方案
推荐阅读
- user-interface - 如何在 Julia、WebIO 和 Blink 中使用 handle(w, “flag”)?
- c# - C# Entity Framework LINQ to Entities 在 SELECT 表达式下添加参数 WHERE 表达式
- python - 我不明白 django 的 path() 是如何工作的
- vue.js - 如何访问 vue.js 中的索引以获取循环元素?
- unity3d - Unity 2D Top-Down 鼠标面临武器旋转问题
- android - 在没有 xml 的情况下以编程方式创建 Listview:不显示任何单元格
- python - 如何在 output.csv 文件中包含“for”循环变量
- python - 超过指定数量。的列用 Pandas 重命名
- angular - Angular:在产品模式下点击刷新后 URL 发生变化
- python - 获取 python sqlite 以支持最新的 sqlite 版本 3.25