2012-06-30 50 views
0

我有一個包含區域的基本項目,我已在此區域註冊了我的路線並使用了小寫的URL擴展名。下面是代碼:C#MVC 4,區域路線,使用主視圖?

using System.Web.Mvc; 

using Web.Modules; 

namespace Web.Areas.Services 
{ 
    public class ServicesAreaRegistration : AreaRegistration 
    { 
     public override string AreaName 
     { 
      get 
      { 
       return "Services"; 
      } 
     } 

     public override void RegisterArea(AreaRegistrationContext context) 
     { 
      context.MapRouteLowercase(
       "Services", // Route name 
       "services/{controller}/{action}/{id}", // URL with parameters 
       new { controller = "Services", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
       new string[] { "Web.Areas.Services" } 
      ); 
     } 
    } 
} 

但現在,當我去http://localhost/services/home它讓我看到我的HomeController的索引視圖,我能做些什麼來解決這個問題?我已經添加了命名空間並將該區域添加到路由數據。

感謝您的任何援助

回答

1

好像你要麼不具備文件夾區域/服務/查看/在所有家庭或文件夾中的索引視圖。在這種情況下,ASP.NET MVC將回退到從Views/Home(無區域)文件夾顯示索引視圖。如果您需要針對您所在地區的不同視圖,則需要在該區域的視圖/ [控制器名稱]文件夾(或當然是共享文件夾)中創建該視圖。