使用 Twitter.Bootstrap.MVC4 是否可以将“null”传递给 客户总监在 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())
;
}
我收到一个错误:对象引用未设置为 NavigationRouteconfigureationExtensions.cs 文件中的对象实例:
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
您不能添加指向同一 Controller /操作的链接:
routes.MapNavigationRoute<CustomerController>("Customer", c => c.Index())
.AddChildRoute<CustomerController>("List", c => c.Index())
或者您收到错误:{“名为 'Navigation-Customer-Index' 的路由已在路由集合中。路由名称必须是唯一的。\r\n参数名称:名称”}
到目前为止,我唯一的解决方法是在 Controller 中添加第二个重复的 Action,并将其命名为 Index2(例如):
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());
}
有没有比复制代码或添加不必要的操作更好的方法?
谢谢,马克
最佳答案
我发现问题出在 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 并卸载了 Twitter Bootstrap Nuget 包,我发现 Global.asax 文件中的条目重复了。删除这些重复条目有效。这 2 个调用至少需要一个条目。
关于asp.net-mvc - Twitter.Bootstrap.MVC4 Nuget 包中的导航路由 Controller 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16167098/