Arron S
Arron S

Reputation: 5537

Changing ASP.NET MVC default folder structure

Is it possible to change around the folder organization to the following and still have MVC work.

P1

P2

etc..

Upvotes: 3

Views: 2133

Answers (4)

Avi Pinto
Avi Pinto

Reputation: 4336

as said before, the Areas feature is what you are looking for. If you are using vs2010, then although you have MVC2, you don't have the tools for creating the areas - these are only available on vs 2008, when you install the MVC2 rc

to make it happen follow the instructions at the following link: http://msdn.microsoft.com/en-us/library/ee671793%28VS.100%29.aspx as you can see the menu options are missing so:

  1. download the example project from there.
  2. build the directory structure at your solution according to the example
  3. change the AreaRegistration.cs to match your area name
  4. add AreaRegistration.RegisterAllAreas(); at the RegisterRoutes function at the global.asax, right after the IgnoreRoute

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

Hope this helps

Upvotes: 1

Paco
Paco

Reputation: 8381

You can create your own viewengine to solve the paths. That sounds like a very strange idea, but the ViewEngine class is actually responsible for 2 things: locating a view and rendering a view to the httpresponse. The thing you have to change is the locating part, you can just inherit the default aspxviewengine and change the view locating part.

Upvotes: 0

Paul Creasey
Paul Creasey

Reputation: 28834

This looks a lot like the new feature area's which is available in MVC 2 though it is currently in preview and will be release with VS 2010.

If you want to do it yourself without using areas then check out this article on view engines

Upvotes: 4

David Hogue
David Hogue

Reputation: 1831

Should be doable, I think the default folder structure is just a suggestion. I've seen before in some documentation that larger projects would likely be split up differently, possibly even among multiple assemblies.

The only thing I would think would cause some trouble would be the views. Since controller actions are mapped to them only by file name. I know there's some way to change them, but I have not had to do so yet.

Upvotes: 0

Related Questions