I am having difficulty getting the DELETE Method on my Controller to fire when submitting the request over ASP.NET Web API. It returns a 404 but I cannot figure out why. The
Try returning HttpResponseMessage
on your Delete method
public HttpResponseMessage Delete( string id )
{
Customer cust = CustomerDb.Customers.Where(c => c.id == id).SingleOrDefault();
if (cust == null)
return new HttpResponseException( HttpStatusCode.NotFound ); // using NotFound rather than bad request
CustomerDb.Customers.DeleteObject(cust);
CustomerDb.SaveChanges();
return new HttpResponseMessage( HttpStatusCode.NoContent );
}
You need to implement Delete method in Controller:
// DELETE /api/values/5
public void Delete(int id) {}
Do you have this defined in your web.config?
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>