Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API 2 Same Route Name Different POST Model Type

I'm trying to have two action methods on an API controller with the same [Route] name, but different parameter types. One which takes a particular object, and the other which takes an array of that object type.

The model binder doesn't seem to be able to distinguish between these and I get the following error returned:

Multiple actions were found that match the request

Is there any way of having two POST methods with the same route but different parameter types?

like image 973
Tophat Gordon Avatar asked Aug 15 '26 17:08

Tophat Gordon


1 Answers

You can't have 2 actions with same routing and same http verb (like Post). And I think that it's beter to use different routings for this example:

/api/controllerName/PostType

/api/controllerName/PostListType

it will be more readible and esier to mantain in future. And when someone else will create client app routing will be self explanatory.

like image 179
garret Avatar answered Aug 19 '26 02:08

garret



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!