"ExceptionMessage": "Multiple actions were found that match the request:

Hi found many helpful link to solve this but nothing is working to me :(. Can any one look at this as where I am going wrong?

Controller :

[ActionName("savebook")] [HttpPost] public HttpResponseMessage PostSaveBook([FromBody]Book product) { return Add(product); } [ActionName("savemobile")] [HttpPost] public HttpResponseMessage PostSaveMobile([FromBody]Mobile product) { return Add(product); }

WebApiRouteConfig.

config.Routes.MapHttpRoute( name: "ControllerOnly", routeTemplate: "api/{controller}" ); // Controller with ID // To handle routes like `/api/VTRouting/1` config.Routes.MapHttpRoute( name: "ControllerAndId", routeTemplate: "api/{controller}/{id}", defaults: null, constraints: new { id = @"^\d+$" } // Only integers ); // Controllers with Actions // To handle routes like `/api/VTRouting/route` config.Routes.MapHttpRoute( name: "ControllerAndAction", routeTemplate: "api/{controller}/{action}" );

Error :

**

"ExceptionMessage": "Multiple actions were found that match the request:

**

--------------Solutions-------------

The first route that you have registered is the RESTful style route, which doesn't include an {action} segment.

As the routes are evaluated in the same order that they are registered, whenever you send a POST request, the controller name will be taken from the URL, and then, the action selector will look for an action whose name starts with Post. In your case there are two actions that fulfill this condition: PostSaveBook and PostSaveMobile.

If the first registered route was the "ControllerAndAction" one, the action would be taken from the URL and the action selector could correctly choose the desired action.

If you want to use the RESTful style, you'd have to use attribute routing to break the ambiguity.

Category:asp.net mvc Time:2018-12-07 Views:1

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 47.570 (s). 16 q(s)