Asp.net mvc url路由。更改网址

时间:2013-07-22 21:17:25

标签: asp.net-mvc-4 asp.net-mvc-routing url-routing asp.net-routing

我的控制器是“/Home/Index".I想要,当我输入url到”/ Dashboard / Index“或”example.com/Dashboard“时,执行我的”/ Home / Index action method“。你能给我起点吗?

1 个答案:

答案 0 :(得分:2)

只需将此路线添加到路线配置中即可。确保在默认路由之前添加

routes.MapRoute(
    name: "HomeRoute",
    url: "Dashboard/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);