Home > Back-end >  HttpDeleteAttribute decorator, valid template? C#
HttpDeleteAttribute decorator, valid template? C#

Time:03-08

is valid the next template route?

[HttpDelete("withdrawal/client/{clientId}/dni/{dni}?catalogNumber={catalogNumber}&warehouse={warehouseId}")]

I receive a exception, with the next description:

RoutePatternException: The literal section '?catalogNumber=' is invalid. Literal sections cannot contain the '?' character.

any help would be nice!

CodePudding user response:

Instead of including the query params in the string literal you can specify them in the function declaration

[HttpDelete("withdrawal/client/{clientId}/dni/{dni}")]
public void Foo([FromQuery] string catalogNumber, [FromQuery] string warehouseId)
{
  ...
}

CodePudding user response:

for url

http://.../withdrawal/client/{clientId}/dni/{dni}?catalogNumber={catalogNumber}&warehouse={warehouseId}

your action should be

[HttpDelete("withdrawal/client/{clientId}/dni/{dni}")]
public IActionResult client(int client, string dni, string catalogNumber, string warehouse)
{
  ...
}

or you can make this url

http://../withdrawal/client/{clientId}/dni/{dni}/{catalogNumber?}/{warehouseId?}")]

your action should be

[HttpDelete("withdrawal/client/{clientId}/dni/{dni}/{catalogNumber?}/{warehouseId?}")]
public IActionResult client(int client, string dni, string catalogNumber, string warehouse)
{
  ...
}
````
  • Related