Html.routelink does not go to the specified route

I have a bunch of routes defined as:

routes.MapRoute(
                name: "ID",
                url: "{category}/{subcategory}/{lowercategory}/{lowercategory1}/{id}/{ignore}",
                defaults: new { controller = "Home", action = "Index", ignore = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "LowerCategory1",
                url: "{category}/{subcategory}/{lowercategory}/{lowercategory1}",
                defaults: new { controller = "Home", action = "Index" }
            );

            routes.MapRoute(
                name: "LowerCategory",
                url: "{category}/{subcategory}/{lowercategory}",
                defaults: new { controller = "Home", action = "Index" }
            );

            routes.MapRoute(
                name: "Subcategory",
                url: "{category}/{subcategory}",
                defaults: new { controller = "Home", action = "Index" }
            );

            routes.MapRoute(
                name: "Category",
                url: "{category}",
                defaults: new { controller = "Home", action = "Index" }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

Now I used routeLink to access the default route, but it didn’t work.

@Html.RouteLink("Create Ad", "Default", new { controller="Electronics",action="Details" })

The request is sent to the indexer home function. What am I doing wrong. How to use routeLink so that the request goes by default.

+4
source share
1 answer

I also had this problem. The code seems to cause RouteLink overload with signature

RouteLink(string linkText, object routeValues, object htmlAttributes)

, routeName , , href , , routeValues ​​ , .

RouteLink(string linkText, string routeName, object routeValues)

:

@Html.RouteLink("Create Ad", routeName: "Default", routeValues: new { controller="Electronics",action="Details" })
+2

All Articles