views:

838

answers:

1

I thought this would be fairly easy, but I'm totally baffled.

I want one controller's views to be at the root level of the application, rather than in a subdirectory for that controller, but I cannot figure it out.

I'd like to have these two urls:

/Info - This should action "Info" on controller "Home"

/Admin/ - This should be action "Index" (default) on controller "Admin"

So far no matter what I've tried, the first route will end up catching both. I can't seem to separate the two.

That Info page doesn't even need a controller, it' static, but I do want to use a master page. There may be a much easier way to pull this off, but I haven't figured that out either.

All I can think of that would work, would be to create an Info controller, and move Views/Home/Info to Views/Info/Index, but that has a certain smell to it.

I was able to do this in rails using:

  map.connect ':controller/:action/:id'
  map.connect ':action', :controller => 'home'
+3  A: 

You just need proper routes. In your case:

routes.MapRoute(
                "Info",
                "Info",
                new { controller = "Home", action = "Info" }

routes.MapRoute(
                "Admin",
                "Admin",
                new { controller = "Admin", action = "Index" }

But i recommend you this approach.

If you need to change default physical location of views/partialviews,
check out how to create custom view engines.

Arnis L.
Didn't think to statically route them, way to hung up on finding the pattern! Still seems there should be a more dynamic way, so I don't have to add a new route for each page.
enth
I thought the same, but I'm not so optimistic anymore. Anyway - routing through attributes looks like a silver bullet to me. :)
Arnis L.
Almost like there is an implicit trailing slash so in the end "/Info" and "/Admin/" end up hitting the same route because "/Info" gets treated as "/Info/". And vice-versa; if I re-order the routes, the first route still catches both. In that case it's like it's treating "/Admin/" like "/Admin".I'm checking out the attribute based routing. Definitely looks promising.
enth
Yeah, but might get quite complicated. I'm afraid that I'll have to dive deep into this soon too. Post here as answer your progress if you manage to find anything interesting. Going to mark this as favorite. :)
Arnis L.