views:

79

answers:

2

In ASP.NET MVC2,

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

  • Views\FOLDER\Account\ChangePass.aspx

Rather than:

  • Views\Account\ChangePass.aspx

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:

  • Views\Categories\

  • Views\Admin\Categories\

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...............................................................

+2  A: 

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 = "" }
        );
Tahbaza
+1  A: 

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

Charlino
Looks very good but I followed the tute and the solution doesn't work, unfortunately I think the code samples are wrong, judging from the comments...
baron
Hmmm, I'll have a look at my solution at home tonight (or over the weekend) and see if I can improve on that walkthrough.
Charlino