如何配置asp.net mvc路由以获取
hocalhost / Products和hocalhost / Search
而不是
hocalhost / Home / Products and hocalhost / Home / Search
即。从路线中删除控制器名称?
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Products", id = UrlParameter.Optional } // Parameter defaults
);
答案 0 :(得分:0)
routes.MapRoute(
"Default",
"{action}/{id}",
new { controller = "Home", action = "Products", id = UrlParameter.Optional }
);
因此:
http://example.com/ => controller=Home, action=Products
http://example.com/Products => contoller=Home, action=Products
http://example.com/Search => contoller=Home, action=Search