私はasp mvcの初心者です。現在、デモプロジェクトの構造は次のようになっています:
Areas -- Comment -- Controller -- HomeController
-- ManageController
Controller -- HomeController
|-- CommentController
|____ PostMsg
|____ DeleteMsg
Views -- Home
| |--- Index.cshtml
|-- Comment
|--- PostMsg.cshtml
|--- DeleteMsg.cshtml
次のようなURLを閲覧すると:
http://localhost/Comment/Manage/ --> return view successfully
http://localhost/Comment/PostMsg --> error "The resource cannot be found."
asp mvc がコントローラーを解決しない理由は誰にもわかります:-(
ここに私のglobal.asax.csルート構成があります:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Demo.Web.Controllers" }
);
ここに私のエリア登録ルート構成があります:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Comment_default",
"Comment/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Demo.Web.Areas.Comment.Controllers" }
);
}
問題 : コメント/PostMsg URL がコメント エリアのコントローラーとして解決された
目標: Comment/PostMsg url は CommentController のアクションとして解決されました
どんな助けでも大歓迎です:-)
解決済みの問題、エリア登録ルート構成の編集 (回避策):
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Comment_default",
"Comment/PostMsg",
new { controller = "Comment", action = "PostMsg", id = UrlParameter.Optional },
new[] { "Demo.Web.Controllers" }
);
context.MapRoute(
"Comment_default",
"Comment/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Demo.Web.Areas.Comment.Controllers" }
);
}