好的,我有一个案例,其中有两个控制器:
HomeController
MathController
我希望我的HomeController的路由保持默认:{controller}/{action}/{id}
。但是我想通过http://myurl/Task/Math/{action}
访问MathController中的操作。
所以我写了以下的RouteConfig:
routes.MapRoute(
name: "Math",
url: "Task/{controller}/{action}",
defaults: new { controller = "Math", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Hem", id = UrlParameter.Optional }
);
使用上述配置,在浏览器中手动输入URL时,两种路由方法都可以正常工作。但是,尝试添加“actionLink”时,它总是使用
Task/{Controller}/{Action}
路由。即使我像这样为Home控制器创建链接: @Html.ActionLink("Hem", "Hem", "Home", null, new { @class = "navbar-brand" })
如何配置我的路由或操作链接,以便获得首选功能?