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 - 当前端和 API 都在同一个 Go 服务器上时,如何保护来自 CSRF 的 REST API?

node.js - 使用 typings 与 npm 安装类型定义文件有什么区别?

c# - IExtenderProvider 根据对象类型仅添加一些属性

c# - 等待 HttpWebRequest.BeginGetRequestStream 结束

python - 从多个rest api流端点读取 - python

rest - ColdFusion 和 REST

azure - 使用 Azure 提高 .Net core 分析应用程序的性能

linux - 通过 Azure Devops 将 .Net Core 3.1 Web 应用部署到 Azure Linux Web 服务时出错

c# - 如何知道受 TFS 2012 checkin 影响的 DLL?

c# - 使用LINQ从表的10个字段中选择3个字段