我有一個MVC 3應用程序與區域,並且我暴露了來自特定區域和控制器的服務。路由到該服務的AreaRegistration內像這樣定義ASP.NET MVC中的ServiceRoute與區域攔截動作鏈接到家
public class AreaAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "Area"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.Routes.Add(
new ServiceRoute("Area/Controller/Service",
new NinjectServiceHostFactory(), typeof(MyService)));
// ....
}
}
在我Global.asax.cs
我只定義了默認路由
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
在我_Layout.chshtml
我有一個鏈接到我的主頁,在這裏我給一個空的區域,我希望它找到HomeController
中的頂部的Controllers
文件夾中的Index
動作(位於Areas文件夾外部):
@Html.ActionLink("Home", "Index", "Home", new { area = "" }, null)
出於某種原因,這個ActionLink
呈現爲
~/Area/Controller/Service?action=Index&controller=Home
如果我註釋掉ServiceRoute,同樣ActionLink
點~/
這是我的期望。
任何想法如何解決這個路由問題?我發現的唯一解決方法是使用此代替:
<a href="@Url.Content("~/")">Home</a>