baron
baron

Reputation: 11191

ASP.NET MVC2 Routing / Folder structure

In ASP.NET MVC2,

How do I change routing/folder structure so I can have

Rather than:

I don't actually want to do it for the account, but I'd like to structure things like that, e.g.

SO I can have two different views like:

These would display completely differently.

All I want to do is to be able to create my own subfolders to push the views into, not a seperate folder for each different controller...............................................................

Upvotes: 0

Views: 1907

Answers (2)

ten5peed
ten5peed

Reputation: 15900

Sounds to me like you need to look into using areas... Have a look at this article for more info:

Walkthrough: Organizing an ASP.NET MVC Application using Areas

Excerpt:

However, some applications can have a large number of controllers, and each controller can be associated with several views. For these types of applications, the default ASP.NET MVC project structure can become unwieldy.

To accommodate large projects, ASP.NET MVC lets you partition Web applications into smaller units that are referred to as areas. Areas provide a way to separate a large MVC Web application into smaller functional groupings. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas).

HTHs,
Charles

Upvotes: 3

Tahbaza
Tahbaza

Reputation: 9546

Go with the asp.net MVC convention for view location; if you want to have different url paths you need to look at creating your own routes, other than the default single route given to you. (See this primer.)

Here's an example of a route that you might add in your Global.asax to have the desired result but you'll have to map this route to a controller action appropriately. Really, your need to decide on the pattern to meet the need of your app...

        routes.MapRoute(
            "FolderRoute",                                             
            "{controller}/{folder}/{action}/{id}",                     
            new { controller = "Home", folder = "yourFolderDefault", action = "Index", id = "" }
        );

Upvotes: 2

Related Questions