Reputation: 549
In this question the Answer suggests using an object as the parameter. What URL would I use to access that? In the OP's first example, my original approach was to overload the action (not sure if overload is the right word) so I had:
public IEnumerable<NTOrder> Get()...
public IEnumerable<NTOrder> Get(int p)...
public IEnumerable<NTOrder> Get(int p, int q)
not elegant, I know, but if I change it to one object I don't know how to format the URL...
Old Code
public IEnumerable<NTOrder> Get() {
//build NTOrderList
return NTOrderList;
}
New Code
public class FilterView
{
public int? fID { get; set; }
public int? fCustomer { get; set; }
public string fSalesPerson{ get; set; }
}
public IEnumerable<NTOrder> Get(FilterView queryFilter) {
//build NTOrderList
List<NTOrder> result = (from order in NTOrderList
where (order.OrderID == queryFilter.fID || queryFilter.fID == null)
&& (order.CustomerID == queryFilter.fCustomer || queryFilter.fCustomer == null)
&& (queryFilter.fSalesPerson == null || order.Salesperson.Equals(queryFilter.fSalesPerson))
select order).ToList();
return result;
}
Upvotes: 0
Views: 2220
Reputation: 549
I found this answer as a possible solution, which basically suggests passing the data as JSON in the url and adding a filter to convert that to a complex object, but as the OP in that post suggests it's not the most elegant way...anybody have a more elegant solution?
Upvotes: 1
Reputation: 888077
The URL would work in exactly the same way, with one querystring parameter for each property in the object.
Upvotes: 0