Question: Why does my action Add gets hit instead of my delete action?
Error message:
"ExceptionMessage": "Multiple actions were found that match the request: Add on type blog.Controllers.api.UsersController Delete on type blog.Controllers.api.UsersController
My angular delete
$scope.delete = function (email) {
$http.post('/api/users/Delete', email).success(function() {
initData();
});
}
alternative tested
//$http({
// url: '/api/users/Delete',
// method: 'POST',
// data: { 'userEmail': email }
// })
// .success(function(data, status, headers, config) {
// initData();
// }).
// error(function(data, status, headers, config) {
// $scope.showError = true;
// });
My MVC 5 api controller
private readonly UserDataAccess _userDataAccess;
// GET: Users/Add
[HttpPost]
public HttpResponseMessage Add(User user)
{
_userDataAccess.AddUser(user);
return Request.CreateResponse(HttpStatusCode.OK);
}
// GET: Users/Delete - never gets hit
[HttpPost]
public HttpResponseMessage Delete([FromBody]string userEmail)
{
_userDataAccess.DelereUserByEmail(userEmail);
return Request.CreateResponse(HttpStatusCode.OK);
}
Please note I do not want to solve it using routing.
ActionNameand adding a route to the action before your default route? SO post