views:

386

answers:

3

This should be simple, but alas...

I've set up an Admin area within my MVC 2 project (single project areas). I've created a couple controllers and their respective view folders. In the AreaRegistration.RegisterArea method, I've specified that I want the default controller to be "Dashboard":

public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller = "Dashboard", action = "Index", id = "" }, new string[] { "Admin" }
        );
    }

If I navigate to url/Admin/Dashboard, the index comes up just fine. What I want, though, is to allow the user to go to url/Admin/ and see the same thing. When I do this, however, I get "The resource cannot be found".

I'm just getting my feet wet with MVC 2's Area implementation, and I don't think I'm doing anything overly complicated... Anyone had the same problem? Do I need to specify a separate route, perhaps at the root, non-area level?

A: 

Try adding this additional route:

        context.MapRoute(
            "Admin_default2",
            "Admin"
            new { controller = "Dashboard", action = "Index", id = "" }
        )
Robert Harvey
yeah, I had tried that, no go. I tried putting it in both the AreaRegistration class as well as the global, prior to the default route.
mannish
Hmm, I can't get it to work in my project either. I will work on it some more later. In the meantime, you will need Phil Haack's route diagnostic tool available here: http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx
Robert Harvey
A: 

Ok, odd. So I added a different area, aptly named "Administration", set the default controller and added the appropriate controller, view, etc. and it worked. The difference? In my first case, I was using "Admin" as the area.

mannish
This warrants further research as I'd like to know why "Admin" was causing trouble. Is there a buried naming conflict somewhere?
mannish
A: 
context.MapRoute(
               "Admin_default3",
               "Admin/{action}",
               new { controller = "Admin", action = "Index" }
               );
Joseph