1

I have been forking on a project for a while now and I ended up having a lot of view for different models. I was wandering whether it is possible to organise these views into sub folders. So just to be clear I want to do the following:

Controllers:

      MyControllers(Folder)->
         MyFirstController.cs
         MYSubcontroller(Folder)->
             MySubController.cs

Views:

      MyFirst(Folder)->
         Index.cshtml
         MYSub(Folder)->
             Index.cshtml
DalekSupreme
  • 1,493
  • 3
  • 19
  • 32

2 Answers2

1

Most basic option would be for your controller routes to specify a view explicitly when returning:

return View("PATH-TO-YOUR-VIEW");

But I'm not a fan of this approach as you lose the nice built in MVC conventions.

By default, the Razor View Engine will use the following conventions when locating views:

~/Views/{1}/{0}.cshtml
~/Views/{1}/{0}.vbhtml
~/Views/Shared/{0}.cshtml
~/Views/Shared/{0}.vbhtml
  1. The view name
  2. The controller name

With this in mind, if you have a controller named MySubController with the default Index action, you would normally have a view file:

~/Views/MySub/Index.cshtml
timothyclifford
  • 6,799
  • 7
  • 57
  • 85
1

You are allowed to put views and controllers wherever you want. You can easily customize view paths on App_Start event. See tha answer in this topic: Can I specify a custom location to "search for views" in ASP.NET MVC?

I would though recommend using the standard project structure and paths. It would makes life easier for other developers that work with your code in the future eventually.

Community
  • 1
  • 1
krzyszt0fd
  • 86
  • 7