小编MyN*_*zse的帖子

无法让 HTTP PUT 请求在 ASP.NET Core 中工作

我正在尝试更新表中的条目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);
}
Run Code Online (Sandbox Code Playgroud)

这是我在 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);
}
Run Code Online (Sandbox Code Playgroud)

编辑 1:我确实有一个 GET 请求列表,它们都可以正常工作。只有 PUT 请求失败了。

c# rest asp.net-core asp.net-core-routing angular

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

asp.net-core ×1

asp.net-core-routing ×1

c# ×1

rest ×1