Reputation: 375
I know there has been a ton of these questions, but I can't seem to figure out why I'm getting a "Multiple actions were found that match the request: " error when calling the PostEmailTemplate action. These are the action methods:
(removed old code)
Update 2: I removed all the methods, set the route back to just the default route, and left the default controller interface. The 2 'get' methods work, but the Post still gives that error. This is now the controller:
public EmailTemplateModel Get(int id)
public List<EmailTemplateName> Get()
public void Post([FromBody]EmailTemplateModel data)
and this is the only route:
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
Upvotes: 0
Views: 250
Reputation: 637
I've thrown up a quick project in order to test your configuration, even though I was quite sure that you've implemented it correctly. Everything works as it should be in my project, I can POST to the controller and get the correct responses etc.
Are you sure you are sending the request properly? Because http://<host>:<port>/api/<controller>
should be the address to which you are sending the POST. No additional action is necessary in the URI, since there is only one POST method. The framework should pick up on the method and use that one automatically. Obviously, a 'multiple actions' error only occurs when there are actually two or more POST methods.
One last resort you could try is to explicitly mention what type of request a method belongs to. This can be done by adding the attributes [HttpGet]
, [HttpPost]
, [HttpDelete]
etc. to that specific method. So in your case, add a [HttpGet]
to both GET methods, and a [HttpPost]
to the POSt method. I'm curious whether or not it will work in that case.
Upvotes: 2