我有一个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>