I have an API Controller Action defined as:
public async Task<IHttpActionResult> ChangePassword(string userId, string password)
My original plan was to pass both userId and password through the data attribute of an AJAX request instead of through the API url.
E.g.:
$.ajax({
url: "/api/users/resetpassword",
data: JSON.stringify({
"userId" : userId,
"password" : password
}),
dataType: "json",
method: "POST",
success: function () {
$("#ResetPasswordModal").modal('toggle');
toastr.success("Password Reset");
},
error: function () {
$("#ResetPasswordModal").modal('toggle');
toastr.error("Password could not be reset");
}
});
However, if I apply the Attribute Route [Route("api/users/resetpassword")]
I get the error
No action was found on the controller 'Users' that matches the request
If I then replace the attribute route with [Route("api/users/{userId}/resetpassword/{password}")], the application is able to find the ChangePassword action successfully.
When applying Attribute Routes to Controller Actions, is it required that all attributes are included in the Route?