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.

Answers


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){..}

Need Your Help

How to check if currently in Wordpress Admin?

wordpress wordpress-plugin admin wordpress-plugin-dev

I am creating my first plugin and have a single function that controls the output. This function has different output based on whether or not it is being viewed from within the WordPress admin vs. ...

JQueryUI draggable “Object doesn't support this property or method” when jquery-ui is included

javascript jquery jquery-ui jquery-ui-draggable

I've got the classic Object doesn't support this property or method message when using JQuery UI.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.