ASP.NET MVC URL Routing Doesn't Give Me Pretty URLs

I created an ASP.NET MVC project and everything works fine, but I have one problem with routing. My Global.asax looks like this:

public static void RegisterRoutes(RouteCollection routes) {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

So, nothing out of the ordinary. My problem is that when I contact the controller / action / params with HTML.ActionLink as follows:

<%= Html.ActionLink("My link", "SomeAction", "SomeController", new {param="someParam"})%>

it must generate (at least, it makes sense in my head) link, such as: http://www.localhost/SomeController/SomeAction/someParam.

Instead, this link is created: http://localhost/SomeController/SomeAction?param=someParam

If I manually create a link that refers to the expected result (SomeController / SomeAction / someParam), the right controller and action are called, but the parameter defined in the action method is always zero.

Any ideas?

+5
2

, , , id param. , - .

+4

:

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

All Articles