Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple HttpPost method in Web API controller
    primarykey
    data
    text
    <p>I am starting to use MVC4 Web API project, I have controller with multiple <code>HttpPost</code> methods. The Controller looks like the following:</p> <p><strong>Controller</strong></p> <pre><code>public class VTRoutingController : ApiController { [HttpPost] public MyResult Route(MyRequestTemplate routingRequestTemplate) { return null; } [HttpPost] public MyResult TSPRoute(MyRequestTemplate routingRequestTemplate) { return null; } } </code></pre> <p><em>Here <code>MyRequestTemplate</code> represents the template class responsible for handling the Json coming through the request.</em> </p> <p><strong>Error:</strong></p> <p>When I make a request using Fiddler for <code>http://localhost:52370/api/VTRouting/TSPRoute</code> or <code>http://localhost:52370/api/VTRouting/Route</code> I get an error: </p> <blockquote> <p>Multiple actions were found that match the request</p> </blockquote> <p>If I remove one of the above method it works fine.</p> <p><strong>Global.asax</strong></p> <p>I have tried modifying the default routing table in <code>global.asax</code>, 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. </p> <pre><code>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" } ); } </code></pre> <p>I am making the request in Fiddler using POST, passing json in RequestBody for MyRequestTemplate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload