So I'm trying to replicate this
SO answer in my code, and I'm failing completely.
I have the default route...
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
And the two function signatures are as follows...
public Models.Observation GetSingleById(int id) {}
public IEnumerable<Models.Observation> GetRangeById(int id, string start, string end, string interval) {}
The goal is that for a URL of /api/controller/12 I should get one "Observation". But if I ask for /api/controller/12?start=x&end=y&interval=z I should be routed to the second function and get a list of items based on the criteria given. But no matter what
URL parameters I provide, I always get routed to the first function. If the SO answer I provide up at the top is correct, then why am I seeing this behavior?
siromega
Member
3 Points
10 Posts
Routing question
Nov 19, 2012 09:48 PM|LINK
So I'm trying to replicate this SO answer in my code, and I'm failing completely.
I have the default route...
routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );And the two function signatures are as follows...
public Models.Observation GetSingleById(int id) {} public IEnumerable<Models.Observation> GetRangeById(int id, string start, string end, string interval) {}The goal is that for a URL of /api/controller/12 I should get one "Observation". But if I ask for /api/controller/12?start=x&end=y&interval=z I should be routed to the second function and get a list of items based on the criteria given. But no matter what URL parameters I provide, I always get routed to the first function. If the SO answer I provide up at the top is correct, then why am I seeing this behavior?
BrockAllen
All-Star
27438 Points
4893 Posts
MVP
Re: Routing question
Nov 19, 2012 10:18 PM|LINK
Routing doesn't work that way. Routing doesn't consider query string params when matching incoming URLs to route patterns.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
siromega
Member
3 Points
10 Posts
Re: Routing question
Nov 19, 2012 10:24 PM|LINK
OK then, I just assumed the SO answer was right. Duly noted!