【发布时间】:2018-11-10 23:48:39
【问题描述】:
我正在尝试更新game 表中的条目。但是,我在 ASP.NET 中的 PUT 请求似乎从未触发,我不知道为什么。
这是 ASP.NET 中的控制器:
[Route("game/{update.GameID}")]
[HttpPut]
public IActionResult updateGame([FromBody]Game update)
{
var result = context.Games.SingleOrDefault(g => g.GameID == update.GameID);
if (result != null)
{
result = update;
context.SaveChanges();
}
return Created("", result);
}
这是我在 Angular 中使用的代码:
url:string;
constructor(private _http: HttpClient) {
this.url = "https://localhost:44359/api/v1/"
};
putGame(id:number, game:Game){
return this._http.put(this.url + "game/" + id, game);
}
编辑 1:我确实有一个 GET 请求列表,它们都可以正常工作。只有 PUT 请求失败。
【问题讨论】:
-
您的其他 ASP.Net 控制器是否成功调用 Angular? Q:你试过用RouteDebugger吗?
标签: c# angular rest asp.net-core asp.net-core-routing