2013-04-23 8 views
5

はそれが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あなたは、同じコントローラ/アクションへのリンクを追加することはできません

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 

:NavigationRouteconfigureationExtensions.csファイル内のオブジェクトのインスタンスに設定されていないオブジェクト参照:エラーが発生します

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

または、次のエラーが表示されます。{「Navigation-Customer-Index」という名前のルートが既にルートコレクションにあります。ルート名は一意でなければなりません\ rを\名前nParameter:名 "}

私の唯一の回避策は、これまでのところ、(例えば)コントローラにおける第二の重複アクションを追加し、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()); 
    } 

は、より良い方法は、コードを複製、または不要なアクションを追加するよりも、ありますか?

おかげで、マーク

答えて

0
NavigationRouteConfigurationExtension.csに

移動します。(これより良い方法を探すが、このハックはそれを動作させる必要があり、その問題は2つのルートを追加することです同じ名前と名前が表示名ではなくルートから生成されます。

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; 
    } 
5

私はGlobal.asaxファイル内の文であることを問題が見つかりました:原因1.09をインストールして、TwitterのブートストラップNugetパッケージをアンインストールする

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

、私は、Global.asaxファイル内のエントリをすることが判明しました繰り返される。これらの重複したエントリを削除することができました。これらの2つのコールには、少なくとも1つのエントリが必要です。

関連する問題