Skip to content

Instantly share code, notes, and snippets.

@erichexter
Created November 22, 2012 01:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erichexter/4128989 to your computer and use it in GitHub Desktop.
Save erichexter/4128989 to your computer and use it in GitHub Desktop.
Example of using NavigationRoutes
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 }
);
}
}
}
@marcorsouza
Copy link

Hi, how do I create the children dynamically?

@dedlfix
Copy link

dedlfix commented Apr 30, 2013

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