私が直面している問題は、同じ名前のコントローラーが 2 つあることです。1 つはメインのコントローラー フォルダーにあり、もう 1 つは管理領域のコントローラー フォルダーにあります。
アクションの結果を直接呼び出すとうまくいきます:
MySite/Admin/Account/GetAccount?userId=1
ルート経由の呼び出しが機能しない
MySite/Admin/User/1/Account
私が間違っていることは何ですか?
Application_Start
AreaRegistration.RegisterAllAreas()
RouteConfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "MyCompany.Controllers" }
);
}
管理者エリア登録
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
context.MapRoute(
"GetUserAccount",
"Admin/User/{userId}/Account",
new { controller = "Account", action = "GetAccount" },
new[] { "MyCompany.Areas.Admin.Controllers" }
);
}
Areas/Admin/AccountController での私のアクションの結果
public ActionResult GetAccount(string userId)
{
// return Account Type
}