Published on: 17 May, 2016

Multiple actions were found that match the request in MVC Web API C# ASP.Net

Tumblr Digg Google Plus

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 }
            );
        }
    }

Comments

Lalit
30 April, 2017
Thanks bro
Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.