asp.net-mvc - Twitter.Bootstrap.MVC4 Nuget 包中的导航路由 Controller 问题

标签 asp.net-mvc asp.net-mvc-3 twitter-bootstrap

使用 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/

相关文章:

javascript - 所需的 angularJS 在指令中不起作用

c# - 扩展现有的 MVC 站点,为每个操作将新数据传递到 ViewData

c# - ASP.Net MVC - 有条件的未经授权的重定向

asp.net-mvc-3 - 我正在运行此错误时,mvc3中缺少程序集引用

javascript - Bootstrap Glyphicon(折叠和展开)不工作

asp.net-mvc-3 - ASP.NET MVC PartialView 不发出验证标记

asp.net-mvc-3 - 如何从 MVC 3 和 IIS7 提供程序集嵌入资源?

javascript - Bootstrap 密码输入切换功能不起作用

html - Bootstrap : v3. 3.7 需要帮助来理解全宽背景颜色问题

css - 如何正确内联此表单?