Michael
Michael

Reputation: 434

MVC Routing with ActionName; Multiple actions were found that match the request

I'm trying to add some custom methods to my controller, but I'm encountering the following error when doing so:

http://localhost/api/process/asdf

Multiple actions were found that match the request

Am I missing something in my WebApiConfig, controller, or my url?

Here is my WebApiConfig:

public static class WebApiConfig {
    public static void Register (HttpConfiguration config) {
        config.Routes.MapHttpRoute(
            name: "ControllerOnly",
            routeTemplate: "api/{controller}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Routes.MapHttpRoute(
            name: "ControllerAndId",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Routes.MapHttpRoute(
            name: "ControllerAndActionGet",
            routeTemplate: "api/{controller}/{action}",
            defaults: new { action = "Get"}
        );
        config.Routes.MapHttpRoute(
            name: "ControllerAndActionAndIdGet",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { action = "Get", id = RouteParameter.Optional }
        );
    }
}

Here is my process controller:

public class ProcessController : BaseApiController
{
    // GET api/process
    public List<Process> Get ()
    {
        return null;
    }

    [HttpGet]
    [ActionName("asdf")]
    public List<Process> asdf () {
        return null;
    }

    [HttpGet]
    [ActionName("fdsa")]
    public List<Process> fdsa (int id) {
        return null;
    }

    // GET api/process/5
    public List<Process> Get (long id)
    {
        return null;
    }

    // POST api/process
    public void Post ([FromBody]string value)
    {
    }

    // PUT api/process/5
    public void Put (int id, [FromBody]string value)
    {
    }

    // DELETE api/process/5
    public void Delete (int id)
    {
    }

}

Upvotes: 2

Views: 858

Answers (1)

Aaryan
Aaryan

Reputation: 36

The best way to find this disambiguation is to use routedebugger.dll and find which of the routes cause the issue.

Upvotes: 2

Related Questions