我遇到一个问题,在返回CreatedAtRoute时出现内部服务器错误。我确认这是问题的根源,我不确定自己做错了什么。
[HttpGet("{steamId64}")]
public async Task<IActionResult> GetBan([FromQuery] string apiKey, [FromRoute] long steamId64)
{
// Code omitted
}
[HttpPost]
public async Task<IActionResult> PostBan([FromQuery] string apiKey, [FromBody] Ban ban)
{
// Code omitted
return CreatedAtRoute("GetBan", new { apiKey, steamId64 = ban.SteamId64 }, ban); // 500
}
最佳答案
您可以通过将Name
值添加到get方法中来实现此目的,如下所示
[HttpGet("{steamId64}", Name = "GetBan")]
public async Task<IActionResult> GetBan([FromQuery] string apiKey,
[FromRoute] long steamId64)
{
// Code omitted
}