【发布时间】:2013-03-12 09:13:34
【问题描述】:
我的项目结构:
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 }
);
}
谢谢...
【问题讨论】:
-
您必须将其路由到其中包含 SomeAction 的控制器。现在,您正在从 AdminController 调用 SomeAction ActionResult。您想从 AreaController 调用 SomeAction。还是我错过了什么?
-
已编辑。对我来说也很难解释。总结,我想调用项目主控制器动作,但它调用区域控制器动作。链接看起来正确,但工作不正常。
标签: asp.net-mvc routing area