Changing the default folder structure of ASP.NET MVC

Is it possible to change the organization structure of the folder to the next and still have MVC work.

P1

  • Controllers
  • Models
  • representation

P2

  • Controllers
  • Models
  • representation

etc..

+3
asp.net-mvc
source share
4 answers

This is very similar to the new feature area that is available in MVC 2 , although it is currently in preview and will be released with VS 2010.

If you want to do it yourself without using areas, then look at this article on viewers

+4
source share

as said earlier, the Areas function is what you are looking for. If you use vs2010, then although you have MVC2, you do not have tools for creating areas - they are only available in vs 2008, when you install MVC2 rc

for this to happen, follow the instructions at the following link: http://msdn.microsoft.com/en-us/library/ee671793%28VS.100%29.aspx since you can see that the menu options are missing, therefore:

  • download the sample project from there.
  • build the directory structure in your solution according to an example
  • change AreaRegistration.cs to match the name of your area
  • add AreaRegistration.RegisterAllAreas (); in the RegisterRoutes function on global.asax, immediately after IgnoreRoute

NOTE: shuold namespaces contain .Areas. for more explanations, a stackoverflow search for asp-net-mvc-2-beta-single-project-area-registration-getting-http-404 (since this is the first time I post a response - SO doesn't let me add more then 1 link, go fugure ..)

Hope this helps

+1
source share

Should be doable, I think the default folder structure is just a suggestion. I have already seen in some documents that larger projects are likely to be split differently, perhaps even among several assemblies.

The only thing that I think will cause some problems will be the views. Since controller actions are mapped to them only by file name. I know there is a way to change them, but I have not had to do this yet.

0
source share

You can create your own view to decide the paths. This sounds like a very strange idea, but the ViewEngine class is actually responsible for 2 things: finding the view and displaying the httpresponse view. The thing you need to change is the location part, you can just inherit the default aspxviewengine value and change the view definition part.

0
source share

All Articles