Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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

share|improve this question
2  
read about $http in docs.angularjs.org –  Ajay Beniwal Nov 15 '13 at 9:47

2 Answers 2

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');
});
share|improve this answer
    
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' ? –  Survivor Nov 16 '13 at 4:22

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;
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.