路线我已经有三个途径如何选择MVC3
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"TestRoute",
"{id}",
new { controller = "Product", action = "Index3", id = UrlParameter.Optional },
new { id = @"\d+" } //one or more digits only, no alphabetical characters
);
routes.MapRoute(
"TestCatalogRoute",
"{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "RsvpForm", id = UrlParameter.Optional } // Parameter defaults
//new { controller = "Product", action = "Index2", id = UrlParameter.Optional } // Parameter defaults
);
}
当我输入网址global.ascx:
http://mydomain.com/
它采用“TestCatalogRoute”路线,但我想要的“默认”路线TT
如何:
- 网址为:
http://mydomain.com
它使用 “默认” 路线 - 网址为:
http://mydomain.com/1
它使用 “TestRoute” 路线(它已经完成了!) - 网址为:
http://mydomain.com/abc
它使用 “TestCatalogRoute” 路线
这是很好的,但我认为“默认”路线呼喊终于被找到:) – Stiger 2012-01-09 07:42:39
你是正确的,zerkms是最好的答案。你的第二条路线是没有ID参数的,所以它不应该是可选的。 – Peter 2012-01-09 08:10:20