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

I'm trying to get filtered data from server using a filtering object I pass to the server side. I have managed to get this working with a post:

angular:

var filter: { includeDeleted: true, foo: bar };
$http({ method: 'post', url: 'api/stuff', data: filter });

web api:

public IEnumerable<StuffResponse> Post([FromBody]Filter filter)
{
    return GetData(filter);
}

But i don't want to use a post for this, I want to use a get. But this does not work:

angular

$http({ method: 'get', url: 'api/stuff', params: filter });

web api

public IEnumerable<StuffResponse> Get([FromUri]Filter filter)
{
    return GetData(filter);
}

Also tried specifying params: { filter: filter }. If i try [FromBody] or nothing, filter is null. With the FromUri i get an object at least - but with no data. Any ideas how to solve this, without creating input parameters for all filter properties?

share|improve this question
    
I think you can't pass data to get method's –  Ramesh Rajendran Feb 28 at 9:20
    
simply remove [FromUrl] attribute, and make sure in Filter class, includeDeleted as a public property, it should work. –  Prashant Lakhlani Feb 28 at 10:30
    
Standard media type formatter would not do this. Custom media type formatter is required. See here codeproject.com/Articles/701182/… –  Chandermani Feb 28 at 13:39
add comment

1 Answer

up vote 0 down vote accepted

A HTTP GET request can't contain data to be posted to the server. What you want is to a a query string to the request. Fortunately angular.http provides an option for it params.

See : http://docs.angularjs.org/api/ng/service/$http#get

share|improve this answer
    
As you see in the example with 'get', I am using 'params'. And I can see the filter object is translated to URL parameters in the request - but the server can't deserialize it to the Filter object –  Trylling Feb 28 at 10:20
    
Filter is a class name, So you can't do this, you can't pass class in a query string, so you need to change the class to string,int,float... –  Ramesh Rajendran Feb 28 at 10:23
add comment

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.