Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC URL routing doesn't give me pretty URLs

I have set up an ASP.NET MVC project, and everything is working great, but I do have one problem with the 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 link to a controller/action/params with an HTML.ActionLink like so:

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

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

But instead it generates a link like this: http://localhost/SomeController/SomeAction?param=someParam

If i manually make a link that links to the expected result (SomeController/SomeAction/someParam) then the right controller and action are called, but the parameter defined in the action method is always null.

Any ideas?

like image 497
Erik Avatar asked Mar 03 '09 19:03

Erik


1 Answers

try adding:

routes.MapRoute(
                    "Default",                                                                                              // Route name
                    "{controller}/{action}/{param}",                                                   // URL with parameters
                    new { controller = "Home", action = "Index", param = "" }  // Parameter defaults
            );
like image 83
Dan Fish Avatar answered Oct 01 '22 06:10

Dan Fish