Search code examples
c#asp.net-mvc-3html.actionlink

how to obsolete controller name from Html.ActionLink in mvc3


I want to obsolete controller name from Html.ActionLink
because I defined my controller in route how to do this,
because if I leave controller name blank in Html.ActionLink
mvc3 automatically put current controller name in Action Link.


Solution

  • If you named your route, you can use RouteLink instead of ActionLink. You'll only have to specify the name of the route, not the controller. Here's an example of a named route:

    routes.MapRoute( "myRoute", 
                     "doStuff/Now", 
                     new {controller = "MyController", action = "DoIt"} );
    

    And here's how to use it in your view

    Html.RouteLink( "Do it!", "myRoute" );
    

    Please see MSDN for full details on RouteLink.