4

ASP.NET MVC 4 を使用して Web アプリケーションを開発しており、コントローラーとビューを次のように整理したいと考えています。

/Controller    
    /Admin
        /LessonController.cs
        /ExerciseController.cs    
    HomeController.cs

/Views
        /Admin
              /Lesson
                   /Index.cshtml
        /Home
              /Index.cshtml

ルートを登録するために次のコードを試しましたが、機能しません。

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 }
            );

            routes.MapRoute(
                name: "Admin",
                url: "Admin/{controller}/action/{id}",
                defaults: new { controller = "Lesson", action = "Index", id = UrlParameter.Optional }
                );

        }

何かアドバイスはありますか?

4

2 に答える 2

10

を使用できますareas。これらは、このタイプの分離用に設計されており、すぐに使用できるある種の分離を提供します。

/Areas
     /Admin
         /Controllers
             /LessonController.cs
             /ExerciseController.cs    
         /Views
             /Lesson
                 /Index.cshtml
             /Exercise
                 /Index.cshtml
/Controllers    
    /HomeController.cs
/Views
    /Home
        /Index.cshtml

ASP.NET MVC でサポートされている標準の規則に従わない場合は、write and register a custom view engine.

于 2013-01-16T21:47:47.727 に答える
1

管理ルートがデフォルトのルートより上になるようにルートを入れ替えてから、アプリケーションを再起動します。

于 2013-11-18T11:42:27.553 に答える