【发布时间】:2014-11-14 18:10:47
【问题描述】:
我遇到了在当前 URL 上添加 URL 的问题,例如: 本地主机/配置 -> 本地主机/配置/配置文件 通过调用@Html.ActionLink(Resources.General.Achievements, "Index", "Profile")
当我真正想要的是:Localhost/Profile
我知道这可以使用 MVC 路由,但我只是不知道如何从视图中调用它们。我使用了 Html.BeginRouteForm,但提交时不会触发此路由。
这是我的路线配置
routes.MapRoute(
name: "Profile",
url: "Profile/{id}",
defaults: new { controller = "Profile", action = "Index" },
namespaces: new[] { "Cobalt.Controllers" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Cobalt.Controllers" }
);
我正在尝试访问根目录中的配置文件控制器和索引操作。我同时拥有配置和管理区域,在调用根目录中的控制器时,我试图摆脱它们。
提前感谢您的帮助
【问题讨论】:
-
您定义的当前路线是什么?请指定您的控制器和操作是什么。然后指定要匹配的网址。
-
我为你更新了我的问题。
-
你想要
@Html.RouteLink(): msdn.microsoft.com/en-us/library/…
标签: c# asp.net asp.net-mvc asp.net-mvc-5 asp.net-mvc-routing