0

Hello i have a server side controller method:

public class CustomerController : ApiController {

public void Delete(IList customers) {

        // handle delete action here....
    }

}

I am using Angularjs , my question is how can i call my delete method from angularjs at client side.

Thanks

1
  • 2
    read about $http in docs.angularjs.org Commented Nov 15, 2013 at 9:47

2 Answers 2

0

You could use an AJAX request with $http:

var customers = [
   { id: 1, name: 'John' },
   { id: 2, name: 'Smith' }
];

$http({ 
    method: 'DELETE', 
    url: '/customer',
    data: customers
}).success(function(data, status, headers, config) {
    alert('success');
}).error(function(data, status, headers, config) {
    alert('error');
});
Sign up to request clarification or add additional context in comments.

1 Comment

method:'DELETE' this is where i have to put the method name? in my case my method'name is Delete so it should put method:'Delete' ?
0

You should probably use $http in angularjs rather than normal http.

function Delete(customer) {
        var promise = $http.post(
            '/customer',
            { customer: customer}
        ).success(function (data, status, headers, config) {
            return data;
        }).error(function (data) {
            return data;
        });
        return promise;
    }

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.