0

I've got a question about routing / navigation with-in the same controller.

Lets say I've got the following route setup

routes.MapLowercaseRoute("SomeAwesomeControllerLookup",
    "SomeAwesomeController/{genre}/{region}/{lookup}",
    new
    {
        controller = "SomeAwesomeController",
        action = "Index",
        genre = UrlParameter.Optional,
        region = UrlParameter.Optional,
        lookup = UrlParameter.Optional,
});

And a Url Action as follows

<a href="@Url.Action("Index", "SomeAwesomeController", new { genre = "Movies" })">Movies</a>

I would expect my URL's to look like "/someawesomecontroller/movies" every time however when I've navigated to a filtered URL like "/someawesomecontroller/movies/boston/today" my menu URL's remain "/someawesomecontroller/movies/boston/today" regardless of the parameters specified in the HTML snipped above.

I can ensure the URL rendered is always "/someawesomecontroller/movies" without hard-coding it?

tereško
  • 58,060
  • 25
  • 98
  • 150
BarendB
  • 277
  • 2
  • 9

1 Answers1

0

As I learnt some other time, the route values are filtered down and used by the Action renderer.

<a href="@Url.Action("Index", "SomeAwesomeController", new { genre = "Movies", region="", lookup="" })">Movies</a>

Should fix your problem. (Could also try "null", but I believe that won't override the existing route values.

Daryl Teo
  • 5,394
  • 1
  • 31
  • 37
  • Not entirely it seemed to transform the parameters into query string values ex: /someawesomecontroller/movies?region=blah&lookup=blah I also tried the following `Movies` But that just emptied the query string parameters. ex: /someawesomecontroller/movies?region=&lookup= Unfortunately one can't assign null to a anonymous parameter. – BarendB Oct 10 '11 at 20:31
  • @BarendB http://stackoverflow.com/questions/7513933/asp-net-mvc-inconsistent-rendering-of-actionlink/7513960#comment9102664_7513960 try this link. That's where I remembered it. – Daryl Teo Oct 10 '11 at 22:00