Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create sub folders in the controller

How can I do in ASP.NET MVC 1, to take sub folders. For example, taking the following folder structure on the controller:

/Controller
  /Blog
     ViewsController.cs
     ArticlesController.cs
  /Customers
     SalesController.cs
     ProductsController.cs
  HomeController.cs

I would like to have the following folder structure in view, each view found your controller:

/Views
  /Blog
     /Views
        Index.aspx
        Admin.aspx
        Show.aspx
     /Articles
        Show.aspx
        Admin.aspx
  /Customers
     /Sales
        Index.aspx
        Totals.aspx
     /Products
        Index.aspx
        Promotions.aspx
  /Home
     Index.aspx
like image 806
andres descalzo Avatar asked Nov 17 '09 13:11

andres descalzo


3 Answers

This is a feature that has been added in ASP.NET MVC 2.0. It is called Areas.

like image 115
Darin Dimitrov Avatar answered Oct 31 '22 08:10

Darin Dimitrov


You could do it using Routes, i.e.

routes.MapAreaRoute("Blogs", 
        "Blog/Views/{controller}/{action}/{id}", 
        new { controller = "Views", action = "Index", id = "" });

That would seem to meet your needs given the data above.

like image 29
Lazarus Avatar answered Oct 31 '22 08:10

Lazarus


In MVC 2 or higher, you just need to right click on the project, then mouse over add, then click Area, and enter in the name of the area. Everything is automatically created for you!

like image 29
rhessinger Avatar answered Oct 31 '22 10:10

rhessinger