5

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?

nkirkes
  • 2,635
  • 2
  • 21
  • 36
  • BTW, that string array param at the end of the MapRoute call is extraneous, I tried adding it in an ignorant attempt at fixing the problem, but since there isn't a controller name conflict in the rest of the project, I think it's useless in this case. – nkirkes Jan 11 '10 at 23:51
  • Not yet. I had to set the proj aside for a couple days for other priorities. I'll dig again this evening though. For the interim I just linked directly to the Area/Controller/Action route I intended the default to be. – nkirkes Jan 21 '10 at 17:12
  • @SocialAddict, check out the solution I provided below. Is your situation similar or were you just curious? – nkirkes Jan 21 '10 at 18:21
  • this works but then causes errors with the shared views as its looking in the root not the area, cant find a tidy way of fixing this, any ideas? – Andrew Jan 22 '10 at 10:18
  • Still happens with MVC4... I have an area called v1 so I doubt the name "admin" has any conflicts whatsoever as you speculate in your own answer. – Lzh Aug 01 '13 at 17:14

3 Answers3

1

Try adding this additional route:

        context.MapRoute(
            "Admin_default2",
            "Admin"
            new { controller = "Dashboard", action = "Index", id = "" }
        )
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • 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. – nkirkes Jan 12 '10 at 00:02
  • 1
    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 Jan 12 '10 at 17:32
1

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.

nkirkes
  • 2,635
  • 2
  • 21
  • 36
  • 4
    This warrants further research as I'd like to know why "Admin" was causing trouble. Is there a buried naming conflict somewhere? – nkirkes Jan 21 '10 at 18:07
0
context.MapRoute(
               "Admin_default3",
               "Admin/{action}",
               new { controller = "Admin", action = "Index" }
               );
Joseph
  • 1