Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 10, 2012 10:11 AM by DarrellNorton
None
0 Points
1 Post
Jul 10, 2012 06:10 AM|LINK
I am starting to use MVC4 Web API project, I have controller with multiple
HttpPost
Controller
public class VTRoutingController : ApiController { [HttpPost] public MyResult Route(MyRequestTemplate routingRequestTemplate) { return null; } [HttpPost] public MyResult TSPRoute(MyRequestTemplate routingRequestTemplate) { return null; } }
Here MyRequestTemplate represents the template class responsible for handling the Json coming through the request.
MyRequestTemplate
Error:
When I make a request using Fiddler for
http://localhost:52370/api/VTRouting/TSPRoute
http://localhost:52370/api/VTRouting/Route
Multiple actions were found that match the request
If I remove one of the above method it works fine
global.asax
I have tried modifying the default routing table in
public static void RegisterRoutes(RouteCollection routes){ routes.MapHttpRoute( name: "MyTSPRoute", routeTemplate: "api/VTRouting/TSPRoute", defaults: new { } ); routes.MapHttpRoute( name: "MyRoute", routeTemplate: "api/VTRouting/Route", defaults: new {action="Route" });}
I am making the request in Fiddler using POST, passing json in RequestBody for MyRequestTemplate
All-Star
86795 Points
9644 Posts
Moderator
MVP
Jul 10, 2012 10:11 AM|LINK
Change your routing to include {action} in the route template. The default should work:
routes.MapHttpRoute( name: "API Default", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } );
habib.osu
None
0 Points
1 Post
Multiple HttpPost method in MVC4 Web API Controller
Jul 10, 2012 06:10 AM|LINK
I am starting to use MVC4 Web API project, I have controller with multiple
methods. The Controller looks like the following:Controller
Here represents the template class responsible for handling the Json coming through the request.
Error:
When I make a request using Fiddler for
or I get an error:If I remove one of the above method it works fine
global.asax
I have tried modifying the default routing table in
, but I am still getting the error, I think I have problem in defining routes in global.asax. Here is what I am doing in global.asax.I am making the request in Fiddler using POST, passing json in RequestBody for MyRequestTemplate
DarrellNorto...
All-Star
86795 Points
9644 Posts
Moderator
MVP
Re: Multiple HttpPost method in MVC4 Web API Controller
Jul 10, 2012 10:11 AM|LINK
Change your routing to include {action} in the route template. The default should work:
routes.MapHttpRoute( name: "API Default", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } );Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.