Jacob Stein
Jacob Stein

Reputation: 322

500, InvalidOperationException: No route matches the supplied values

I'm having an issue where I'm getting an internal server error when returning CreatedAtRoute. I confirmed it's the source of the issue, I'm not sure what I'm doing incorrectly.

[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
}

Upvotes: 1

Views: 1615

Answers (1)

khoroshevj
khoroshevj

Reputation: 1137

You can achieve this by adding Name value to your get method like this

[HttpGet("{steamId64}", Name = "GetBan")]
public async Task<IActionResult> GetBan([FromQuery] string apiKey, 
[FromRoute] long steamId64)
{
    // Code omitted
}

Upvotes: 3

Related Questions