I'm currently having a problem with a Web Api I'm working on.
I have a controller with two Get methods. one which returns a list of objects. the other which returns a list of the same object, but filtered based on some parameters that are passed in. Like so:
public IList<MyObject> Get(int id)
{
//Code here looks up data, for that Id
}
public IList<MyObject> Get(int id, string filterData1, string filterData2)
{
//code here looks up the same data, but filters it based on 'filterData1' and 'filterData2'
}
I cannot make the routes work for this. Especially as the Api help page seems to display the same url multiple times.
my routes look like:
config.Routes.MapHttpRoute(
name: "FilterRoute",
routeTemplate: "api/Mycontroller/{Id}/{filterData1}/{filterData2}",
defaults: new { controller = "Mycontroller" }
);
config.Routes.MapHttpRoute(
name: "normalRoute",
routeTemplate: "api/Mycontroller/{Id}",
defaults: new { controller = "Mycontroller" }
);
Anyone know?
Also, is it possible to change my filtered method to something like
public IList<MyObject> Get(int Id, FilterDataObject filterData)
{
//code here
}
Or can you not pass complex objects on a Get?