2012-10-25 58 views
0

我在asp.net的MVC 3,我的工作有三個方面在我的項目一樣,如何配置在asp.net mvc的途徑與領域

MyProject/Areas/Blogs 
MyProject/Areas/Forums 
MyProject/Areas/Groups 

在這三者之中,博客的看法是啓動視圖。對於我已經設置了作爲globla.ascx

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

和BlogAreaRegistration.cs,

context.MapRoute(
       "Blogarea_Default", 
       "{controller}/{action}/{id}", 
       new { controller = "Blog", action = "Blog", id = UrlParameter.Optional } 
      ); 

和ForumAreaRegistration.cs,

context.MapRoute(
       null, 
       "Forums/{action}/{id}", 
       new {controller="Forums", action = "Forum", id = UrlParameter.Optional } 
      ); 

和GroupsAreaRegisration.cs,

context.MapRoute(
     "Groups_default", 
     "Groups/{controller}/{action}/{id}", 
     new { controller = "Groups", action = "Group", id = UrlParameter.Optional } 
    ); 

Here Forum和博客工作,因爲我的願望,但集團不工作,它總是顯示404資源未找到頁面所以請指導我,如果我在這個過程中有任何錯誤。

回答

2

嘗試改變

context.MapRoute(
     "Groups_default", 
     "Groups/{controller}/{action}/{id}", 
     new { controller = "Groups", action = "Group", id = UrlParameter.Optional } 
    ); 

爲:

context.MapRoute(
     "Groups_default", 
     "Groups/{action}/{id}", 
     new { controller = "Groups", action = "Group", id = UrlParameter.Optional } 
    ); 
+0

@Rogulski:我做了上述改變,但我沒有得到所需的輸出。它再次顯示相同的404錯誤 –

+0

看起來你的網址產生'404'? –

0

您應該刪除從您的GroupsAreaRegisration.cs代碼塊Groups/{controller}/ - 那麼它應該工作。我想刪除{controller}/,所以代碼將是:

context.MapRoute(
    "Groups_default", 
    "Groups/{action}/{id}", 
    new { controller = "Groups", action = "Group", id = UrlParameter.Optional } 
); 

此外,在BlogAreaRegistration.cs我會用Blog取代{controller},因爲你可能會得到相當意外的結果並非如此。在這裏完整的代碼將是

context.MapRoute(
    "Blogarea_Default", 
    "Blog/{action}/{id}", 
    new { controller = "Blog", action = "Blog", id = UrlParameter.Optional } 
);