0

I have these routes:

 routes.MapRoute(
                 "ActionOnly",
                 "{action}",
                 new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                 new { action = "Klub|Historie" });

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

            // Hrac/Jmeno_hrace
            routes.MapRoute(
                 "Hrac",
                 "Hrac/{name}",
                 new { Controller = "Hrac", Action = "Name" }
            );


            // pro aktivaci uzivatele který se registroval, ale jeste nepotvrdil email
            routes.MapRoute(
                "Activate",
                "Account/Activate/{username}/{key}",
                new { controller = "Account", action = "Activate", username = UrlParameter.Optional, key = UrlParameter.Optional }
            );

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

Why @Html.ActionLink("Domů", "Index", "Home") is creating website.com/Administrace/Home and not website.com/Home/index and how can I fix it?

Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182

2 Answers2

0

Your Administrace route is swallowing all controllers.

You should change it to hard-code the controller name:

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

If you want that route to work for multiple controllers, you should replace it with an area (or just add a constraint).

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Use @Html.RouteLink instead with the route name being default

Link to something that might help: What's the difference between RouteLink and ActionLink in ASP.NET MVC?

Community
  • 1
  • 1
Matt Seymour
  • 8,880
  • 7
  • 60
  • 101