Civilian
Civilian

Reputation: 654

HTML.ActionLink() generating incorrect URLs

I'm having difficulty getting HTML.ActionLink() create correct links.

When I am at http://localhost:49242/

My options are:

But when I navigate to http://localhost:49242/en-us/PinnedSites my options are:

All of these urls fail, of course.

Here's my html:

.cshtml (Html / razor)

<li id="nav_pinning">
    @Html.ActionLink( "pinned sites", "index", "PinnedSites")</li>
<li id="nav_addons">
    @Html.ActionLink("add-ons", "index", "addons")</li>
<li id="nav_control">
    @Html.ActionLink("tracking protection lists", 
                    "index", 
                    "trackingprotectionlists",
                    null,
                    null)</li>

Global.asax.cs

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("favicon.ico");
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default", // Route name
            "{culture}/{controller}/{action}", 
            new { culture = "en-us", 
                controller = "Home", 
                action = "Index", 
            }
        );
    }

Where is my problem? Is it possible that /PinnedSites/ is not actually going to the PinnedSitesController?

(And I will be actively watching this, please comment if you want me to try things or provide more code.)

Upvotes: 3

Views: 876

Answers (1)

Jesse
Jesse

Reputation: 8393

Do you have a HomeController as part of your project? If so you should register the default controller along the lines of:

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

However, that aside have you tried simply making the Route directly to your PinnedSites controller?

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("favicon.ico");
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default", // Route name
            "{culture}/{controller}/{action}", 
            new { culture = "en-us", 
                controller = "PinnedSites", 
                action = "Index", 
            }
        );
    }

Upvotes: 2

Related Questions