I have some routes setup in my global.asax.cs file like this:
routes.MapHttpRoute(
name: "ColorsRoute",
routeTemplate: "api/{controller}/{action}/{styleId}",
defaults: new
{
controller = "Cars",
action = "Colors"
}
);
The controller:
public Dictionary<string, string> Colors(string styleid)
{
//returns a dictionary of colors and ids
}
The thing is when using a url like this:
localhost:58645/api/cars/colors/18752867
Doesnt pick up the styleId, but it works using it traditionally like this:
localhost:58645/api/cars/colors?styleid=18752867
Any ideas on why this is happening?
UPDATE:
These routes are working fine with calls like this "domain.com/api/cars/makes/new":
routes.MapHttpRoute(
name: "MakesRoute",
routeTemplate: "api/{controller}/{action}/{state}",
defaults: new
{
controller = "Cars",
action = "Makes"
}
);
Controller:
public Dictionary<string, string> Makes(string state)
{
//return dictionary of makes and ids
}
Here are the additional routes i have:
routes.MapHttpRoute(
name: "ModelsRoute",
routeTemplate: "api/{controller}/{action}/{make}/{state}",
defaults: new
{
controller = "Cars",
action = "Models"
}
);
routes.MapHttpRoute(
name: "YearsRoute",
routeTemplate: "api/{controller}/{action}/{modelId}/{state}",
defaults: new {
controller = "Cars",
action = "Years"
}
);
routes.MapHttpRoute(
name: "StylesRoute",
routeTemplate: "api/{controller}/{action}/{make}/{model}/{year}",
defaults: new {
controller = "Cars",
action = "Styles"
}
);