I'm trying to implement a Controller with more than one POST method in one controller. I have the following:
public class PatientController : ApiController
{
[HttpGet]
public IEnumerable<Patient> All() { ... }
[HttpGet]
public Patient ByIndex(int index) { ... }
[HttpPost]
public HttpResponseMessage Add([FromBody]Patient patient) { ... }
}
And i have a this on my routing:
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
"API_1",
"{controller}/{index}",
new { index = RouteParameter.Optional });
Everything works as expected :)
Now, i would like to add the following action:
[HttpPost, ActionName("save")]
public void Save(int not_used = -1) { ... }
Without adding anything to routing, i get the following error in to Fiddler: Multiple actions were found that match the request.
If i add this to my routing (as a second or first, doesn't matter):
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
"API_2",
"{controller}/{action}/{not_used}",
new { not_used = RouteParameter.Optional },
new { action = "save|reset" }); // Action must be either save or reset
Ill get the same error in to Fiddler.
Is this even possible? Can i have more than one POST, with different (type) parameters, in one controller?