views:

28

answers:

2

I have an existing project, and I want to intorduce Areas and keep my original code as it is.

i.e

/web/controllers
/web/views
..
/web/areas/new-area/
/web/areas/new-area/controllers
..

Do I have to modify routing for this to work? i.e. default area is ""?

+2  A: 

Yes it is possible. Every area has an independent routing registration file so you can still keep controllers and views as before.

Darin Dimitrov
*Isn't working* is not a very precise problem description. It's more often employed by simple users and not software developers.
Darin Dimitrov
A: 

Your original route registration probably looks something like this:

routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new
                {
                    controller = "Home",
                    action = "Index",
                    id = ""
                }  // Parameter defaults
            );

The key is that your area has an AreaRegistration where you set up the routes for that area. Inside the area registration, it looks like this:

context.MapRoute(
                "MyArea_default",
                "MyArea/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );

Notice how the first segment of the route that you've defined has "MyArea" (or call it whatever you want). This is how the area is differentiated from the default routes.

So, to conclude, you will not have to modify the routes you already have set up in your global.asax. You will set up routes for your area and they will be differentiated as shown above and conflicts will be avoided.

Steve Michelotti