Created
November 22, 2012 01:50
-
-
Save erichexter/4128989 to your computer and use it in GitHub Desktop.
Example of using NavigationRoutes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Web.Routing; | |
// You need to add this using statement to use the MapNavigationRoute extension method. | |
using NavigationRoutes; | |
namespace MvcApplication13 | |
{ | |
public class RouteConfig | |
{ | |
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | |
//This is the first Navigation route | |
// RouteName DisplayName Url Defaults | |
routes.MapNavigationRoute("Home-navigation", "Home" , "", new { controller = "Home", action = "Index" }); | |
//This is the second Navigation route | |
// RouteName DisplayName Url Defaults | |
routes.MapNavigationRoute("About-navigation", "About" , "about", new { controller = "Home", action = "About" }); | |
routes.MapRoute( | |
name: "Default", | |
url: "{controller}/{action}/{id}", | |
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } | |
); | |
} | |
} | |
} |
Use the strongly typed version
var fooNavRoute = routes.MapNavigationRoute<FooController>("Foo", f => f.Index());
// repeat following as often as needed
fooNavRoute.AddChildRoute<FooController>("Child", f => f.Child());
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, how do I create the children dynamically?