views:

13

answers:

1

I have an MVC 2.0 application where I have a list of items that can be browsed by their first letter and I have a tab on the master page for the whole list of items.

What I would like is that the tab on the master page always should go to:

/items

And there are the letters of the abc that go to the items starting with the letter. So for example for the a it should go to:

/items/a

To generate the link for the tab in the master page I use:

Url.Action("Index", "Items")

The problem is that if I am looking at the items starting with a, so I am at /items/a then the tab also points to this location and not just /items.

Anyone knows why is that, and what can I do to always point to /items in the tab using proper UrlHelper methods?

EDIT: and my routs are the following:

    routes.MapRouteLowercase(
        "DefaultPrefixed",                                              // Route name
        "{controller}/{action}/{q}",                           // URL with parameters
        new { controller = "Items", action = "Index", q = "" },  // Parameter defaults
        new { q = @"[a-z]{1}" }                                        // constraint
    );

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

This will depend on your routes but assuming you are using the default route:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Users", action = "Index", id = UrlParameter.Optional }
);

You can always optional route values to blank:

Url.Action("Index", "Items", new { id = string.Empty })
Darin Dimitrov
Thanks a lot for your answer. I did try what you have suggested, but then the letter is put in the tab link as a querystring parameter, so I get then items?q=a..... It might be beacause of my routs, I have put the routs in my question.
apolka
The reason this happens is because of your second route. Those two routes are the same as they use the same pattern: `{string}/{string}/{string}` and there's no way to disambiguate between them. Remove the second route (the one with id).
Darin Dimitrov