Routing optional parameters with dashes in MVC

Posted by Géza on Stack Overflow See other posts from Stack Overflow or by Géza
Published on 2010-05-20T11:48:32Z Indexed on 2010/05/20 11:50 UTC
Read the original article Hit count: 163

I've made an routing definition like this:

 routes.MapRoute("ProductSearch", "Search-{MainGroup}-{SubGroup}-{ItemType}",
   new {
    controller = "Product",
    action = "Search",
    MainGroup = "", SubGroup = "", ItemWebType = ""});

It is not working if the parameters are empty. Actually it resolves the url, so Url.Action method resolves the path "Search-12--" but the link is not working, so the GET of the page is not working

With slashes it is working the Url.Action method makes "Search/12"

"Search/{MainGroup}/{SubGroup}/{ItemType}"

is it somehow possible to correct it?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-routing

Related posts about asp.net-mvc