TheJoeIaut
TheJoeIaut

Reputation: 1532

Web API Routing - multiple actions were found that match the request

I got this Route:

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { id = UrlParameter.Optional }
        );

And this Actions:

    [System.Web.Http.HttpPost]
    [System.Web.Http.ActionName("GetLoginSeed")]
    public object GetLoginSeed()

    [System.Web.Http.HttpPost]
    [System.Web.Http.AllowAnonymous]
    [System.Web.Http.ActionName("Authenticate")]
    public object PerformLogin(JObject jr)

This is the Post Request:

    http://localhost:61971/api/Login/GetLoginSeed

Why I always get an multiple actions were found that match the request error?

Upvotes: 8

Views: 30147

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038800

I got this Route:

What you have shown is a route for MVC controllers. I hope you realize that Web API controllers are an entirely different thing. They have their own routes defined in the ~/App_Start/WebApiConfig.cs.

So make sure tat you have included the {action} token in your Web API route definition (which I repeat once again has nothing to do with your MVC route definitions):

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{action}"
);

Upvotes: 39

Related Questions