Published on: 17 May, 2016

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

Posted by andy | 1749 views 0 likes 0 favourites 1 comments
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
Commented on: 30 Apr, 2017 05:28:40 PM
Thanks bro
Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Share your article with us and add your own google adsense account to earn extra money. Plus, you can promote a link back to your site.
Related Articles
Published on: 27 October, 2017
In this article, you will learn how to download a file in Web API MVC. We will use HTTP Get API method to perform this download action with one single parameter which will accept the file name.
Published on: 28 October, 2016

In this tutorial you will learn how easily you can implement a simple checkout express using C# MVC Web API. We will create a really simple shopping cart where customers can add and delete their cart items before proceed to payment.