我的项目结构:
Controller
AdminController
HomeController
区域添加后我的项目结构我在项目中添加了一个管理区域,
Areas
Admin
Controller
SomeController
Controller
AdminController
HomeController
然后所有链接都断开了。例如
@Html.ActionLink(
"go to some action",
"SomeAction",
"Admin",
new { area = "" },
null)
当我写上面的链接时,它会将我路由到www.myDomain.com/Admin/SomeAction
,但这是区域操作,我想路由到 AdminController 操作。
我怎样才能做到这一点?我应该更改区域或控制器名称吗?
更新
以上链接输出:
domain/Admin/SomeAction
// I expect that is AdminController/SomeAction
// but not. There is SomeAction in my admin controller
// I get this error "The resource cannot be found."
// because it looks my expected, but it works unexpected
// it tries to call AdminArea/SomeController/SomeAction
更新 2
例如:
@Html.ActionLink(
"go to some action",
"SomeAnotherAction",
"Admin",
new { area = "" },
null)
对于上面的链接,我没有收到任何错误,因为我所在的地区有 SomeAnotherAction。
区域登记
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
谢谢...