views:

122

answers:

1

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?

I made a sample with the default mvc project: Only added: before default route:

    routes.MapRoute(DefaultSearch", "Search-{MainGroup}-{Subgroup}-{ItemType}",
        new {controller = "Home",action = "About", MainGroup = "", 
              Subgroup = "", ItemType = ""});

in Home/index.aspx:

<a href="<%=Url.Action("About", "Home", new {maingroup = "2", subgroup = "", itemType = ""}) %>">
    Search</a>

In HomeController:

public ActionResult About(string maingroup, string subgroup, string itemtype)
{
  return View();
}

Click on the link and 404

+1  A: 

What version do you use? in mvc 2 you can use UrlParameter.Optional as default values for routes.

Sadegh
Unfortunately MVC 1. I solved my problem totally by totally override the RouteBase class' GetVirtualPath and GetRouteData functions
Géza