DEV Community

Discussion on: Using cancellation tokens on ASP.NET Core MVC actions

Collapse
 
loferreiranuno profile image
loferreiranuno • Edited

Just a question.

How do we handler parameters on the Method?

I've tryed set something such


Task Method(string tag, CancellationToken ctx) and I'm getting an 415 Code.

Collapse
 
joaofbantunes profile image
João Antunes

Hi,

I'm not really sure of what may cause this (but I have a vague idea of such problem in the past), so I'll drop a couple of ideas that may be able to help you investigate.

  • Depending on if it's a GET, POST, etc, try to use an attribute to indicate from where the parameter comes from, e.g.: [FromRoute], [FromQuery], [FromBody].
  • Instead of the first idea, you could instead use the [ApiController] attribute, which will use some defaults to resolve the parameters, e.g. simple types come from route or query, complex ones come from body.