1

Which is the right way to pass parameter in a DELETE in AngularJS?

This call is not working:

 $http.delete("api/testDelete",
             { 
              Id:5
             }
             ).success(function (data) {
                alert('Exit status ' + data);
            });

This call is working:

  $http.delete("api/testDelete",
             { 
               { params: { Id: 5 } }
             }
             ).success(function (data) {
                alert('Exit status ' + data);
            });

This is the C# Web Api being called:

[HttpDelete]   
  public bool testDelete(int Id)
  { return true; }

Why do i have to use params? Is it possible to pass an object? Thanks

2 Answers 2

2

You need to send the id in the URL:

$http.delete("api/testDelete/5")
     .success(function (data) {
        alert('Exit status ' + data);
     });
Sign up to request clarification or add additional context in comments.

Comments

0

You can send params to the api in two ways:

  • In the query string:

    $http.delete("api/testDelete",{ 
         { params: { Id: 5 } }
     }).success(function (data) {
         alert('Exit status ' + data);
     });
    
  • In the body of the request:

     $http.delete("api/testDelete",{ 
         { data: { Id: 5 } }
     }).success(function (data) {
         alert('Exit status ' + data);
     });
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.