0

I have this simple API controller in a NetCore 2.2 web game that is supposed to return a list of monsters based on the dungeonID(Guid).

So I use the URL, passing in the guid of the dungeonID, to that controller like this:

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

But when I step through the code, I just see all zeroes for the dungeonID:

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

        return Json(monsters);
    }

This returns nothing because, for reasons I don't know, dungeonID is always all zeroes.

But this does work if I hard-code in the 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);
}

I've seen lots of posts similiar to mine, like these:

asp.net webapi 2 post parameter is always null

Post parameter is always null

But nothing seems to work.

How do I add the ability to pass in a Guid parameter?

Thanks!

1 Answer 1

1

One point is 2f14c8gf-2e7e-466a-bcbg-f4440e92b3dg is not a GUID/UUID . Just try with a correct GUID :

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.