{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nPostperson on type choreManagerWEBAPIproject.Controllers.peopleController\r\nPostRegister on type choreManagerWEBAPIproject.Controllers.peopleController","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}
The above error leads me to believe that my RouteConfig is incorrect.
Right now I'm making the following call locally:
$.ajax({
url: "http://localhost:17438/api/people/PostRegister/",
type: "POST",
data: JSON.stringify({ name: 'Jeff', email: 'jv@test.com', phone: '5551212', carrierName: 'SPRINT'}),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
When this gets called the error displays: Internal Server Error
As you can see I'm calling the PostRegister.
[ResponseType(typeof(string))]
[HttpPost]
[HttpOptions]
public string PostRegister([FromBody] newUserRegistration newReg)
{
...
var json = JsonConvert.SerializeObject(parent.familyID);
return json;
}
My RouteConfig:
routes.MapHttpRoute("DefaultApiWithId", "Api/{controller}/{id}", new { id = RouteParameter.Optional }, new { id = @"\d+" });
routes.MapHttpRoute("DefaultApiWithAction", "Api/{controller}/{action}");
routes.MapHttpRoute("DefaultApiWithActionAndId", "Api/{controller}/{action}/{id}", new { id = RouteParameter.Optional }, new { id = @"\d+" });
routes.MapHttpRoute("DefaultApiGet", "Api/{controller}", new { action = "Get" }, new { httpMethod = new HttpMethodConstraint("Get") });
routes.MapHttpRoute("DefaultApiPost", "Api/{controller}", new { action = "Post" }, new { httpMethod = new HttpMethodConstraint("Post") });
I'm thinking that it should be going to this config:
DefaultApiWithAction
When I debug into the WebAPI controller it goes to this line in the people
controller:
public class peopleController : ApiController
{
private FamilyChoreManagerEntities db = new FamilyChoreManagerEntities();
...
}
But then I get the error message. And then it stops debugging.
I do have 2 methods for POST:
public void Postperson(person person)
public string PostRegister([FromBody] newUserRegistration newReg)