NimChimpsky
NimChimpsky

Reputation: 47290

Multiple actions were found that match the request using POST method .net mvc

Controller looks like the following, the get works ok, but when a post is called recieve the referenced :

[ActionName("import")]
public void PostImport([FromBody]string file = "myString")
{}

[ActionName("something")]
public void PostSomething()
{}

[ActionName("bool")]
public Boolean GetBool()
{}

routes register like below :

config.Routes.MapHttpRoute(
  name: "DefaultApi",
  routeTemplate: "api/{controller}/{id}",
  defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
  name: "ControllerAndAction",
  routeTemplate: "api/{controller}/{action}"
);
routes.MapRoute(
  name: "Default",
  url: "{controller}/{action}/{id}",
  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

The request I am using is this :

curl -H "Content-Type: application/json" -d '{"file":"myOtherString"}' http://localhost:6
1393/api/admin/import

Upvotes: 0

Views: 1144

Answers (1)

Andy Nichols
Andy Nichols

Reputation: 3002

The URL /api/admin/import matches two different routes.

It matches DefaultApi with a controller of "admin" an id of "import".

It also matches ControllerAndAction with a controller of "admin" and action of "import".

So it can't work out which route to use

Upvotes: 1

Related Questions