If you are completely new to MVC Web API and encounter a problem with an error message saying Multiple actions were found that match the request. It means you need to modify your Web API register class to provide additional action request in the code.
If you open the WebApiConfig.cs under the App_Data folder under your root project, you will have the following code by default.
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } }
What you need to do is to modify the routeTemplate and add extra action parameter into the code. The changes would be like below.
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); } }