获取请求不通过 url 向 api 控制器发送参数

Get request not sending parameter via url to the api controller

我在 NetCore 2.2 网络游戏中有这个简单的 API 控制器,它应该 return 基于 dungeonID(Guid) 的怪物列表。

所以我使用 URL,将 dungeonID 的 guid 传递给该控制器,如下所示:

https://localhost:44361/MonsterList/GetMonsters/2f14c8gf-2e7e-466a-bcbg-f4440e92b3dg

但是当我单步执行代码时,我只看到 dungeonID 全为零:

    public async Task<JsonResult> GetMonsters(Guid dungeonID)
    {
        var monsters = await _context.MonsterList.Where(c => c.DungeonID == (dungeonID)).ToListAsync();

        return Json(monsters);
    }

这 return 没什么,因为,出于我不知道的原因,dungeonID 总是全为零。

但是如果我在 dungeonID 中进行硬编码,这确实有效:

https://localhost:44361/MonsterList/GetMonsters

public async Task<JsonResult> GetMonsters()
{
    var monsters = await _context.MonsterList.Where(c => c.DungeonID == Guid.Parse("2f14c8gf-2e7e-466a-bcbg-f4440e92b3dg")).ToListAsync();

    return Json(monsters);
}

我看过很多与我类似的帖子,例如:

Post parameter is always null

但似乎没有任何效果。

如何添加传入 Guid 参数的功能?

谢谢!

有一点是 2f14c8gf-2e7e-466a-bcbg-f4440e92b3dg 不是 GUID/UUID 。只需尝试使用正确的 GUID :

https://localhost:44384/api/values/GetMonsters/2e6ae748-10c2-4e23-84c3-9d3db7c09631