david
david

Reputation: 1

Html ActionLink Route problem

i have defined the following Routes:

routes.MapRoute("Blog",
            "Blog/{controller}/{action}",
            new { controller = "Test", action = "Index" });

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

When i call http://localhost/ all Links are wrong and go to the Blog:

@Html.ActionLink("About", "About", "Home") creates the following URL:

localhost/Blog/About

but it should create

localhost/About

Why does HtmlActionLink always prefix the urls with the "Blog"?

Upvotes: 0

Views: 1122

Answers (1)

SLaks
SLaks

Reputation: 888107

ActionLink will the first route that matches the parameters you passed to it.
Since your Blog route contains the controller and action parameters, it will use that route.

You should change your Blog route to be more specific.

Upvotes: 1

Related Questions