Using the Twitter.Bootstrap.MVC4 is it possible to pass "null" to the Customer controller in the 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: Object reference not set to an instance of an object 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 can't add a link to the same controller/action:
routes.MapNavigationRoute<CustomerController>("Customer", c => c.Index())
.AddChildRoute<CustomerController>("List", c => c.Index())
Or you get the error: {"A route named 'Navigation-Customer-Index' is already in the route collection. Route names must be unique.\r\nParameter name: name"}
My only workaround so far, is to add a second duplicate Action in the controller, and name it 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());
}
Is there a better way, than duplicating code, or adding unnecessary actions?
Thanks, Mark
I found the problem to be the statements in Global.asax file:
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);
Due to installing 1.09 and uninstalling the Twitter Bootstrap Nuget package, I found the entries in Global.asax file to be repeated. Removing these duplicate entries worked. You need at least one entry for these 2 calls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With