MVC3 - add folder to controllers?

I want to find out if an extra folder can be added to the Controller folder. My reason is quite simple: I want to separate the project administration and client side.

Example: I have a controller named Post that has the actions Index, Details, Delete, Create, Edit . I want to make one controller as user controller, which will consist of Index, Details and another controller as admin controller, which will consist of Delte, Create, Edit . Then I can easily distinguish what is and put the administrator check on the whole admin class.

Another reason is because I want my URL to manage my site to look like /admin/post/delete , and not /post/delete .

So this is possible, and if so, what would be the best way to implement this?

+6
source share
3 answers
+8
source

This is just an agreement on placing controllers in the Controllers folder.
In fact, MVC finds the controller in the currently loaded assembly .
You can place them even in other assemblies .
Thus, it was not possible to create additional folders inside the controllers.

+2
source

If you use Ruby on Rails, yes you can. In the config / routes.rb route files, add the following:

  map.namespace :admin do |admin| admin.resources :posts end 

Go to your terminal and go to your project, follow the rake routes. Now you get your message controller under the admin space ... and your url will be:

 .../admin/posts 
-2
source

Source: https://habr.com/ru/post/916974/


All Articles