0

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..

0

3 Answers 3

1

from your api definition it seems you need it as data and not as a query params

$http({
    url: "/api/Customer/GetInvoicesForCustomer", 
    method: "GET",
    data: {'element': element}
 });
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

0

Change

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

to

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

Update : Please try following way to call API

$http({
    url: "/api/Customer/GetInvoicesForCustomer", 
    method: "GET",
    params: {element: element}
 });

3 Comments

what error you get in console..?and there are multiple ways to call this get.pleas see the updated answer
Updated code threw an exception in console and it didn't come to the controller. "GET localhost:8080/KtvCustomer/api/Customer/……owAll%22:false%7D,%22SearchString%22:null,%22SortOn%22:4,%22SortBy%22:1%7D 404 (Not Found)" But previous came to the controller with element as null.
it might be because i forget to add "/" infront of "api/custo.."

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.