Twitter.Bootstrap.MVC4 を使用すると、ExampleLayoursRoute.config でCustomer コントローラーに「null」を渡すことができます。
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
同じコントローラー/アクションへのリンクを追加することはできません:
routes.MapNavigationRoute<CustomerController>("Customer", c => c.Index())
.AddChildRoute<CustomerController>("List", c => c.Index())
または、次のエラーが表示されます: {「'Navigation-Customer-Index' という名前のルートは既にルート コレクションにあります。ルート名は一意である必要があります。\r\nパラメータ名: 名前」}
これまでの私の唯一の回避策は、コントローラーに 2 つ目の複製アクションを追加し、それに 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());
}
コードを複製したり、不要なアクションを追加したりするよりも良い方法はありますか?
ありがとう、マーク