0

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

1
  • Do you want to change how MVC looks up the aspx file that contains your view (a ViewEngine feature) or the shape of the URLs that are used to access your resources (a Routing feature)? Commented Aug 26, 2010 at 0:48

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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

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 = "" }
        );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.