views:

161

answers:

1

I need to have a parameter as part of my ASP MVC URL before Controller and Action:

http://www.mydomain.com/company1/Home

or

http://www.mydomain.com/company1/Clients/Detail/1

(Ideally I would like to have this as a sub-domain like this: http://company1.mydomain.com/Clients/Detail/1 so any answers solving this one is also appreciated)

I call this parameter Account. I tried adding something like this to the routing map: "{account}/{controller}/{action}/{id}" but it gives me a 404 error when trying something like http://www.mydomain.com/company1/Home

Here is the RegisterRoutes in Global.asax:

        public static void RegisterRoutes(RouteCollection routes)
        {
           routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("TestRoute", "{account}/{controller}/{action}/{id}");

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

Is there anything special I have to do when organising my Views folder or Controller actions?

+2  A: 

Your error sounds like you are not giving a default for action in your route defaults.

John Downey
That's what I'm thinking, too, but with out the exact routes it's hard to tell.
tvanfosson
You are absolutely right guys! Adding defaults fixed the issue. But how can I get hold of the account value in my controller actions?
Khash
Add a string parameter to your action method with the same name and it should get filled in by MVC.
John Downey