ASP MVC Routing with > 1 parameter

I have the following route defined

            new { controller = "Home", action = "Index", name = "", projectName = "" }

This route actually works, so if I type in the browser

/Milestone/Edit/Co-Driver/Feature complete

It correctly goes to the Milestone controller, the edit action and passes the values.

However, if I try and construct the link in the view with a url.action -

<%=Url.Action("Edit", "Milestone", new {, projectName=m.Project.title})%>

I get the following url

Milestone/Edit?name=Feature complete&projectName=Co-Driver

It still works, but isn't very clean. Any ideas?


When constructing and matching routes in ASP.NET routing (which is what ASP.NET MVC uses), the first appropriate match is used, not the greediest, and order is important.

So if you have two routes:


in that given order, then the first one will be used. The extra values, in this case projectName and name, become query parameters.

In fact, since you've provided default values for {projectName} and {name}, it's fully in conflict with the default route. Here are your choices:

  • Remove the default route. Do this if you don't need the default route any more.

  • Move the longer route first, and make it more explicit so that it doesn't match the default route, such as:

        new { controller = "Home", action = "Index", name = "", projectName = "" }

    This way, any routes with controller == Home will match the first route, and any routes with controller != Home will match the second route.

  • Use RouteLinks instead of ActionLinks, specifically naming which route you want so that it makes the correct link without ambiguity.

Need Your Help

IIS Authentication across servers .net-2.0 iis-6 single-sign-on .net-1.1

My production environment involves a pair of IIS 6 web servers, one running legacy .NET 1.1 applications and the other running .NET 2.0 applications. We cannot install .NET 2.0 alongside 1.1 on th...

Jquery $(element).hide().blur().show() showing up all elements

javascript jquery html

i have 3 drop down list on my page.2 have display set to none.When i click on drop down list(note just click, do not select) and mouse hover on the hello text the first drop down is reset but the d...