Reputation: 920
I need to pass a single parameter to a Web API POST method.
Following is my AJAX call:
$http({ method: 'POST', url: "customers/ProcessCustomer/" + customerId })
.success(function (data) {
});
where customerId
is a Guid
.
And my controller:
[HttpPost]
[Route("customers/ProcessCustomer")]
public void ProcessCustomer(Guid id)
{
//do some stuff
}
But I only get a 404 not found error when I do this. What am I doing wrong?
Upvotes: 0
Views: 191
Reputation: 60664
When you POST
to an action method, the data isn't embedded in the URL. Instead, use the data
field of the settings object in your ajax call:
// I didn't recognize what library you're using for the AJAX call, so this is jQuery
$.ajax('customer/ProcessCustomer', {
data: { id: customerId },
success: function() { /* woohoo! */ }
});
Upvotes: 0
Reputation: 24222
You're using attribute routing but you haven't specified an id
parameter in the route. Use this instead:
[Route("customers/ProcessCustomer/{id}")]
See Attribute Routing in Web API 2 for more examples.
Upvotes: 1