WebAPI Controller is not being reached on DELETE command

前端 未结 3 848
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 13:40

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

3条回答
  •  不思量自难忘°
    2020-12-24 14:06

    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 );
    }
    

提交回复
热议问题