views:

69

answers:

1

This is sort of a duplicate of http://stackoverflow.com/questions/2045761/trouble-setting-a-default-controller-in-mvc-2-rc-area

But his answer doesn't satisfy me, because it doesn't work.

I have the following

/Areas/TestArea/Controllers/HelloController
/Areas/TestArea/Views/Hello/Index

/Controllers/HomeController
/Views/Home/Index

With the following routes:

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

routes.MapRoute(
    "Default2", // Route name
    "TestArea/{controller}/{action}/{id}", // URL with parameters
    new { controller = "Hello", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

I added the second one to try and get http://servername/TestArea to work as if it were http://servername/TestArea/Hello but was met with no success. The basic http://servername/ works as intended.

So the question is: how do you return a default controller in an area?

Edit: I have uploaded a sample project to show what I mean: http://beginningasp.net/TestAsync.zip

A: 

Try to register Default2 route before the default route and set area=yourareaname in the default values

routes.MapRoute(
    "Default2", // Route name
    "TestArea/{controller}/{action}/{id}", // URL with parameters
    new { controller = "Hello", action = "Index",area="TestArea",  id = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Gregoire
A good, solid point. After doing so I get the following: "The view 'Index' or its master was not found. The following locations were searched:" with a list of all the root view folders. None of the area's folders were searched.
Krisc
@Krisc do you use mvccontrib or other lib for your routing?
Gregoire
Nope, this is a "blank" MVC2 project (for testing).
Krisc
Do you register your areas in you global.asax?
Gregoire
Yes. It turns out that the area registration was done first, so it was using that route which does not have the default controller!
Krisc