Ellbar
Ellbar

Reputation: 4054

MVC - Url links

I have following routing in my app:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapRoute(null, "{article}",
            new { controller = "Home", action = "Article" });

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

This makes my urls to articles looks like that (examples), and it works fine:

www.website.com/article-example-1
www.website.com/funny-photos-of-the-day
www.website.com/something-about-dogs  
www.website.com/how-to-repair-car

etc...

But I have problem with Views from another controllers. For example on the view from Administrator controller when I add url link like that:

<a href="article-example-1">Article example 1</a>

then it redirect me not to:

www.website.com/article-example-1 

but to:

www.website.com/Administrator/article-example-1

How to make links to point to right link (without controller in url).

Upvotes: 1

Views: 561

Answers (1)

Ellbar
Ellbar

Reputation: 4054

I found the source of problem. There must by "/" slash before article-example-1 in the link and everything works fine:

Wrong:

<a href="article-example-1">Article example 1</a>

Correct:

<a href="/article-example-1">Article example 1</a>

Upvotes: 1

Related Questions