Dimitri
Dimitri

Reputation: 3

Attribute Routing with RoutingParameter

I currently have a set of action methods in a web api controller that use Attribute Routing.

[RoutePrefix("Paper")]...

[Route("Shape/Octagon/{id:minlength(1)}]
public IEnumerable<sampleShape> PostactionName(string id){..}

[Route("Shape/Hexagon/{id:minlength(1)}]]
public IEnumerable<sampleShape> PostactionName(string id){..}

which would work for the following URIs

api/Paper/Shape/Octagon/"1,2,3"
api/Paper/Shape/Hexagon/"3,2,1"

but becomes unusable once the id parameter becomes to long. Is there anyway to have routing use the parameter id as a form data rather than part of the URI but still keep the Route attribute.

Upvotes: 0

Views: 138

Answers (1)

Claudio Redi
Claudio Redi

Reputation: 68400

You can use FromBody attribute to let the engine know that parameter will come from post body

[RoutePrefix("Paper")]...

[Route("Shape/Octagon"}]
public IEnumerable<sampleShape> PostactionName([FromBody]string id){..}

[Route("Shape/Hexagon"}]]
public IEnumerable<sampleShape> PostactionName([FromBody]string id){..}

Upvotes: 1

Related Questions