public
Last active

Example of using NavigationRoutes

  • Download Gist
RouteConfig.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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 }
);
}
}
}

Hi, how do I create the children dynamically?

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());

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.