Problems with navigation routes Controller on Twitter. Bootstrap.MVC4 Nuget package

Using Twitter.Bootstrap.MVC4 allows you to pass "null" to the Client Controller in ExampleLayoursRoute.config:

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapNavigationRoute<HomeController>("Home Page", c => c.Index());

        routes.MapNavigationRoute<CustomerController>("Customer", null)  <-- pass null here
              .AddChildRoute<CustomerController>("List", c => c.Index())
              .AddChildRoute<CustomerController>("Add", c => c.Create())
            ;
    }

I get an error: the object reference is not installed in the object instance in the NavigationRouteconfigureationExtensions.cs file:

  public static NamedRoute ToDefaultAction<T>(this NamedRoute route, Expression<Func<T, ActionResult>> action,string areaName) where T : IController
    {
        var body = action.Body as MethodCallExpression; <--- Error here

You cannot add a link to the same controller / action:

        routes.MapNavigationRoute<CustomerController>("Customer", c => c.Index())
              .AddChildRoute<CustomerController>("List", c => c.Index())

Or you get an error message: {"The route with the name" Navigation-Customer-Index "is already in the route collection. The route names must be unique. \ R \ nParameter: name"}

My only workaround so far is to add a second duplicate of Action to the controller and its name is Index2 (for example):

public ActionResult Index()
    {
        return View(db.Customers.Where(x => x.UserName == User.Identity.Name).ToList());
    }

 public ActionResult Index2()
    {
        return View(db.Customers.Where(x => x.UserName == User.Identity.Name).ToList());
    }

, ?

,

+5
2

Global.asax:

    BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);
        BootstrapMvcSample.ExampleLayoutsRouteConfig.RegisterRoutes(RouteTable.Routes);
        BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);
        BootstrapMvcSample.ExampleLayoutsRouteConfig.RegisterRoutes(RouteTable.Routes);

- 1.09 Bootuprap Nuget Twitter , Global.asax . . .

+5

NavigationRouteConfigurationExtension.cs. , , ( ). , .

    public static NavigationRouteBuilder AddChildRoute<T>(this NavigationRouteBuilder builder, string DisplayText, Expression<Func<T, ActionResult>> action,string areaName="") where T : IController
    {
        var childRoute = new NamedRoute("", "", new MvcRouteHandler());
        childRoute.ToDefaultAction<T>(action,areaName);
        childRoute.DisplayName = DisplayText;
        childRoute.IsChild = true;
        builder._parent.Children.Add(childRoute);

        //builder._routes.Add(childRoute.Name,childRoute);
        builder._routes.Add(Guid.NewGuid().ToString(), childRoute);

        return builder;
    }
0

All Articles