13
エリアのフォルダは次のようになります。Mvcエリアルーティング?
Controller
UserController
GetAllUsers
エリアルート登録
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new { controller = "Branch|AdminHome|User" }
);
}
プロジェクトルート登録
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "MyApp.Areas.Admin.Controllers" });
}
:
Areas
Admin
Controllers
UserController
BranchController
AdminHomeController
プロジェクトディレクトリは次のようになり3210
私がこのように経路を設定したとき:http://mydomain.com/User/GetAllUsers
リソースが見つかりません。エラー(404)が表示されます。 UserControllerをAreaに追加した後にこのエラーが発生します。
このエラーを修正するにはどうすればよいですか?あなたは、コントローラの名前空間を台無しにしました
私はこの分野に対応する名前空間に混乱しています。この例では、名前空間MyApp.Areas.Admin.Controllersはフォルダ階層と一致しますが、名前空間の定義は任意です。つまり、プログラマが望むコントローラクラスに名前空間を割り当てることができるということです。または、フォルダ階層に一致させるために名前空間を必要とするいくつかのasp.net mvc規則がありますか? – Howiecamp
@ Howiecamp Visual Studioのデフォルトの動作は、ネームスペースをフォルダ階層に一致させることです。これは、通常はすべての.netプロジェクト(MVCプロジェクトだけでなく)に表示されます。 –