0

I have two MapRoute in global asax.`

            routes.MapRoute(
           "AutoGeneratedURLHandler", // Route name
           "{modulepath}/{controller}/{action}/{id}", // URL with parameters
           new { id = UrlParameter.Optional } // Parameter defaults
       );      



        //default route
        routes.MapRoute(
           "Default", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new { controller = "Account", action = "Logon", id = UrlParameter.Optional } // Parameter defaults
       );`

And I have two link on masterpage.

  <li><%:Html.ActionLink("Card Types", "Index", "CardType", new { modulepath="CardManagement" },null)%></li>
                 <li><%:Html.ActionLink("Home Page", "Index", "Home")%></li>

After I click Card Types link, Home Page link becomes "/CardManagement/Home/Index" instead of "/Home/Index".

Route values remember "modulepath" and add it auto to home page link. But I dont want this. How can I make it not add module path to url?

whitestream
  • 691
  • 1
  • 7
  • 14
  • When I use `Html.RouteLink` and `RedirectToRoute` instead of `Html.ActionLink` and `RedirectToAction`, it works as expected. But is not there another solution? Should not I use `Html.ActionLink` and `RedirectToAction` in the project? – whitestream Nov 11 '11 at 15:45

1 Answers1

0

Instead of ActionLink, you could use a RouteLink and send it down your default route. Another option is to not use the ActionLink helper and just roll the link on your own:

<a href="home/index">Home</a>
Billy Coover
  • 3,827
  • 5
  • 36
  • 50
  • Should not I use Html.ActionLink and RedirectToAction in the project? If I use these two, I will have this problem. Is not there a solution for `ActionLink` ? – whitestream Nov 11 '11 at 15:48
  • Take a look here: http://stackoverflow.com/questions/780643/asp-net-mvc-html-actionlink-keeping-route-value-i-dont-want/780812#780812 – Billy Coover Nov 11 '11 at 15:49
  • Not the "new id" part but his explanation of how the URL is derived. – Billy Coover Nov 11 '11 at 15:58