c# - 500, 无效操作异常 : No route matches the supplied values

标签 c# rest asp.net-core .net-core

我在返回 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
}

关于c# - 500, 无效操作异常 : No route matches the supplied values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48977357/

相关文章:

rest - 使用 REST API 远程创建 Jenkins 作业

asp.net - IIS 7 的最大默认 POST 请求大小 - 如何增加 64kB/65kB 限制?

asp.net-core - 在导航属性上使用虚拟

docker - .NET Core Web应用程序无法在Docker容器中运行

c# - SMTP 服务器需要安全连接或客户端未通过身份验证。

c# httpwebrequest getResponse() 卡住并挂起我的程序

c# - ASP.Net WebApi STA模式

c# - Web API通用错误处理

ruby-on-rails - Rails RESTful API + 对仅允许 GET/POST 的客户端的支持 - 这可能吗?

c# - 了解 Entity Framework 多对多关系。为什么我的代码在尝试向其中添加更多数据后会崩溃?