Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top