我有我的global.asax.cs部分航線的安裝文件是這樣的:ASP.NET網頁API路由未能趕上參數
routes.MapHttpRoute(
name: "ColorsRoute",
routeTemplate: "api/{controller}/{action}/{styleId}",
defaults: new
{
controller = "Cars",
action = "Colors"
}
);
控制器:
public Dictionary<string, string> Colors(string styleid)
{
//returns a dictionary of colors and ids
}
的事情是,當使用這樣的URL:
localhost:58645/api/cars/colors/18752867
犯規拿起styleId,但它的工作原理傳統使用它是這樣的:
localhost:58645/api/cars/colors?styleid=18752867
關於爲什麼會發生這種情況的任何想法?
UPDATE:
routes.MapHttpRoute(
name: "MakesRoute",
routeTemplate: "api/{controller}/{action}/{state}",
defaults: new
{
controller = "Cars",
action = "Makes"
}
);
控制器:
public Dictionary<string, string> Makes(string state)
{
//return dictionary of makes and ids
}
這裏
這些線路與電話這樣的 「domain.com/api/cars/makes/new」 工作正常是我的額外路線:
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"
}
);
你說你有一些路線,但你只顯示一個。是否有其他路線在您的Global.Asax – cecilphillip 2012-04-15 14:34:39