2

I have this method in ASP.NET Core:

   [HttpDelete("id:int")]
    public async Task<IActionResult> Delelte(int id)
    {
       // do sth
    }

Now when I call this api via swagger the generated url is :

https://localhost:44357/api/mycontroller/id:int?id=2

I expected to have a url without querystring like api/mycontroller/2

The problem is that I want to call this api from code and in code I call it like this api/mycontroller/2 but it return 404

2 Answers 2

2
[HttpDelete("id:int")]

Should be

[HttpDelete("{id:int}")]

The parameters are encapsulated in angle brackets {} with optional constraints like int. Everything outside of that is considered a static part of the route url.

See also Routing in ASP.NET Core

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

Comments

1

The issue seems to come from the way you have fromatted your HttpDelete attribute.

Try to format it this way instead :

[HttpDelete("{id}")]

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.