【发布时间】:2012-03-03 07:32:30
【问题描述】:
我有一个区域Area1 和控制器Home,它是Index 方法。
我还使用控制器Home 创建了另一个区域Area2,它是Index 方法。
在Area1 中,我有应该在Area2 中打开Index 页面的操作链接。
@Html.ActionLink("Link to another area index", "Index", "Home", new { area = "Area2" }, null)
但是当我点击这个链接时,它首先转到Area1/Home/Index!
为什么会这样。一定要这样还是可以直接去Area2/Home/Index?
这让我有问题,因为在 Area1/Home/Index 中我需要一些参数,当这种情况发生时,这个 valuer 是 null 或错误的,这让我有问题。我必须做错事。
更新
区域1路由
public override void RegisterArea(AreaRegistrationContext context)
{
context.Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
context.MapRoute(
"Area1_home",
"{country}/{city}",
new { controller = "Home", action = "Index", country = UrlParameter.Optional, city = UrlParameter.Optional }
);
context.MapRoute(
"Area1_default",
"Area1/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
区域 2 路由:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Area2_default",
"Area2/{controller}/{action}/{id}",
new { controller="Home", action = "Index", id = UrlParameter.Optional }
);
}
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing asp.net-mvc-areas