how can i use parameter routing?
my project use .Net 6.0
like: https://localhost:7203/v1/users/123/items?action=delete
i want use code
[HttpPost]
[Route("/v1/users/{userId}/items")]
public void Delete(string userId)
{
//TODO...
}
CodePudding user response:
[HttpDelete("/v1/users/{userId}/items")]
public void Delete([FromRoute] string userId)
{
//TODO...
}
CodePudding user response:
If you really need use POST
to execute delete action
then your parameter name MUST the same as action's parameter
example:
if your uri is
https://localhost:7203/v1/users/123/items?action=delete
[HttpPost]
[Route("/v1/users/{userId}/items")]
public void Delete([FromRoute]string userId, string action)
{
// Use your action string to decide action
}
BUT it is better to specify httpDelete to your delete action