2011-09-14 5 views
0

return View()をコントローラに呼び出すと、メインの~/Views/{Controller}/フォルダとメインの~/Views/Shared/フォルダのビューを検索しようとします。 ~/{Area}/Views/{Controller}/フォルダーには表示されません。asp.net-mvc2 - コントローラがView()を返すときに領域を考慮していない

areaのルート値をMapRoute関数に追加しようとしましたが、ルートのDataTokensプロパティに "area"の 'datatoken'を追加しようとしました。

ここに何か不足していますか?

これはMapRoute呼び出しです:見て

routes.MapRoute("Product", "Products/{GroupName}/{CategoryId}/{CategoryName}/{ProductId}/{ProductName}/{PageName}", New With {.Area = "Products", .controller = "Products", .action = "Product", .PageName = ""}, New With {.CategoryId = "[0-9]*", .ProductId = "[0-9]*"}) 
+0

MapRoute機能を投稿できますか? – ericb

+0

MapRouteの呼び出しを追加しました – ReFocus

+0

オーバーライドされたAreaNameがグローバルアプリケーションのAreaフォルダのパスと同じであることを確認してください。 – kaps

答えて

0

こんにちは一般的なもの:

はあなたの登録したエリアのマッピングとエリアマッピングをお持ちですか? 両方の場所でコントローラの名前が同じですか? Global.asaxの中

領域マッピングの例
線参照:AreaRegistration.RegisterAllAreasを(); //これは、あなたが

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

    routes.MapRoute(
     "Default", // Route name 
     "{controller}/{action}/{id}", // URL with parameters 
     new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
    ); 

} 

protected void Application_Start() 
{ 

    AreaRegistration.RegisterAllAreas(); // This is part you neeed to do 
    RegisterRoutes(RouteTable.Routes); 
    ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); 
} 

}

を行うためにneeed一部であり、すべての領域がマッピングまたはマッピングファイルがどこかに設定している必要があります。ここ 例

名前空間プロジェクト管理エリア /// パブリッククラスAdministratorAreaRegistrationの { /// /// 登録:AreaRegistration { /// /// に地域の名前を取得します。登録される。 /// ///登録する領域の名前。 パブリックオーバーライド文字列領域名 { get { return "Administrator"; }}

/// <summary> 
    /// Registers an area in an ASP.NET MVC application using the specified area's context information. 
    /// </summary> 
    /// <param name="context">Encapsulates the information that is required in order to register the area.</param> 
    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute(
      "Administrator_default", 
      "Administrator/{controller}/{action}/{id}", 
      new { action = "Index", id = UrlParameter.Optional }); 
    } 
} 

}

あなたはこのルーティングチェックに問題がある場合。

私は、このガイドを使用することをお勧めし、すべてのルーティングのためのテストを作成します。私たちは通常、地域をどうのよう http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx

0

は、我々はAeaRegistraionファイル(FooAreaRegistration.cs)を追加し、AREANAMEとRegisterArea()メソッドをオーバーライド。 AreaNameグローバルアプリケーションに対してAearRegistrationファイルが存在するフォルダの相対パスに設定します。以下は例です。

public class FooAreaRegistration : AreaRegistration 
{ 
    /// <summary> 
    /// Get the Area Name 
    /// </summary> 
    public override string AreaName 
    { 
     get { return "ParentApp/AreaFolder"; } 
    } 

    /// <summary> 
    /// Map and Route the area 
    /// </summary> 
    /// <param name="context"></param> 
    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     if (null != context) 
     { 
      //context.maproute goes here    
     }    
    } 
} 
関連する問題