2

I use ActionLink in my MVC4 website as follows:

@Html.ActionLink("home", result: MVC.Home.Index())

after redirect, the url comes in the "www.mysite.com/home/index" form.

How can I prevent showing "home/index" or "index" in url??

2 Answers 2

1

You are seeing index in url because html.actionlink generates tag with href home/index. Instead of using helper html.actionlink use tag directly with href as home and have a default route which routes to index. But in this case you might loose the ability to route correctly when deployed in virtual directory.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to supply defaults to the corresponding route in your route configuration like so:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(name: "Default",  url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.