PAVITRA PAVITRA - 3 months ago 12
AngularJS Question

Web API sending an object to the Controller via Java Script

I'm using Angular/C# Web API.

In my JavaScript service I have the following.

invoicesForCustomer = $http.get('/api/Customer/GetInvoicesForCustomer',
{params:element} );


In the Web API Controller

[HttpGet]
public InvoiceListModel GetInvoicesForCustomer(InvoiceListOptionsModel element)


but this element object is always null. I tried this for a single parameter and it worked.
Any help on sending an object via querystring to Web API controller..

Answer

Hi Try changing [HttpGet] to [HttpPost]. Also your

$http({
    url: "/api/Customer/GetInvoicesForCustomer", 
    method: "GET", ---> This should be post too
    data: {'element': element}
 });