2

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?

1
  • 1
    Can you show your exact routing set up from global.asax? Commented May 5, 2009 at 19:18

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.