我有这些路线:
routes.MapRoute(
"ActionOnly",
"{action}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { action = "Klub|Historie" });
routes.MapRoute(
"Administrace", // Route name
"Administrace/{controller}/{action}/{id}", // URL with parameters
new { controller = "Administrace", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
// Hrac/Jmeno_hrace
routes.MapRoute(
"Hrac",
"Hrac/{name}",
new { Controller = "Hrac", Action = "Name" }
);
// pro aktivaci uzivatele který se registroval, ale jeste nepotvrdil email
routes.MapRoute(
"Activate",
"Account/Activate/{username}/{key}",
new { controller = "Account", action = "Activate", username = UrlParameter.Optional, key = UrlParameter.Optional }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
为什么@Html.ActionLink("Domů", "Index", "Home")
正在创建website.com/Administrace/Home而不是website.com/Home/index,我该如何解决?
答案 0 :(得分:0)
您的Administrace
路线正在吞下所有控制器。
您应该将其更改为硬编码控制器名称:
routes.MapRoute(
"Administrace", // Route name
"Administrace/Administrace/{action}/{id}", // URL with parameters
new { controller = "Administrace", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
如果您希望该路由适用于多个控制器,则应将其替换为区域(或仅添加约束)。
答案 1 :(得分:0)
使用@ Html.RouteLink而路由名称为default
链接到可能有用的内容: What's the difference between RouteLink and ActionLink in ASP.NET MVC?