2011-12-15 59 views
4

我將默認路由對象設置爲區域(也稱爲「Beheer」)內的控制器(「Beheer」)。MVC3到區域的默認路徑不搜索區域內的視圖

像這樣:

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

可以發現,控制和區域內的動作很好,但它無法找到視圖,因爲它只是看起來在這些位置:

~/Views/Beheer/Index.aspx 
~/Views/Beheer/Index.ascx 
~/Views/Shared/Index.aspx 
~/Views/Shared/Index.ascx 
~/Views/Beheer/Index.cshtml 
~/Views/Beheer/Index.vbhtml 
~/Views/Shared/Index.cshtml 
~/Views/Shared/Index.vbhtml 

雖然它應該看在這個位置:

~/Beheer/Views/Beheer/Index.aspx 

我該如何使它搜索視圖th ERE?

我已經嘗試過:

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

我想這(與命名空間):

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

但是沒有什麼變化。它在正確的控制器中輸入正確的操作,但找不到視圖。

回答

2

您應該在區域註冊中添加您的路線。 BeheerAreaRegistration有一個屬性設置區域名稱。


    public class BeheerAreaRegistration : AreaRegistration 
    { 
     public override string AreaName 
     { 
     get 
     { 
      return "Beheer"; 
     } 
     } 

    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute("Default", // Route name 
       "{controller}/{action}/{id}", // URL with parameters 
       new { controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults); 
    }
+0

這已經出現在BeheerAreaRegistration中。我應該改變這裏的東西嗎? – David 2011-12-15 13:45:09

0

我有這個問題,發現我需要完全限定的命名空間,我有與它找到正確的觀點,直到我殺了IIS進程,某種奇怪的緩存什麼的,也許問題。

new[] { "Areas.Beheer" } 

可能成爲

new[] {"myApp.Areas.Beheer.Controllers"} 

也許你的問題是與我相似 - 也許不是。