2011-10-13 5 views
1

조직이라는 영역이 있습니다. 이 영역에는 Url.Action 링크가있는보기가 있습니다.영역이있는 ASP.NET MVC 라우팅

기본적으로 작업 이름을 전달하면 조직 영역의 현재 컨트롤러에서 작업을 호출합니다.

컨트롤러 폴더 (영역이 아님)에 컨트롤러가 있고 그 컨트롤러에서 작업을 호출하고 싶습니다.

기본적으로이 동작은 모든 영역에서 호출 할 수 있습니다. 이것을 달성하는 가장 좋은 방법은 무엇입니까?

이것이 완전히 잘못된 길인 경우에는 제안을 할 수 있습니다.

감사합니다,

편집 - 여기 당신은 그에 대한 특정 경로를 만들 필요가

Global.asax에

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

     routes.MapRoute(
      "Columns", 
      "Columns/Columns/{ID}/{idList}", 
      new { controller = "Columns", action = "UserColumnList" } 
     ); 

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

    } 

OrganisationsAreaRegistration.cs

public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute(
      "Organisations_view", 
      "Organisations/{id}/View", 
      new { controller = "Manage", action = "View" } 
     ); 

     context.MapRoute(
      "Organisations_general", 
      "Organisations/{id}/General", 
      new { controller = "Manage", action = "General" } 
     ); 

     context.MapRoute(
      "Organisations_addressbook", 
      "Organisations/{id}/AddressBook", 
      new { controller = "Manage", action = "AddressBook" } 
     ); 

     context.MapRoute(
      "Organisations_departments", 
      "Organisations/{id}/Departments", 
      new { controller = "Manage", action = "Departments" } 
     ); 

     context.MapRoute(
      "Organisations_people", 
      "Organisations/{id}/People", 
      new { controller = "Manage", action = "People" } 
     ); 

     context.MapRoute(
      "Organisations_events", 
      "Organisations/{id}/Events", 
      new { controller = "Manage", action = "Events" } 
     ); 

     context.MapRoute(
      "Organisations_journal", 
      "Organisations/{id}/Journal", 
      new { controller = "Manage", action = "Journal" } 
     ); 

     context.MapRoute(
      "Organisations_tasks", 
      "Organisations/{id}/Tasks", 
      new { controller = "Manage", action = "Tasks" } 
     ); 

     context.MapRoute(
      "Organisations_edit", 
      "Organisations/{id}/Edit", 
      new { controller = "Manage", action = "Edit" } 
     ); 

     context.MapRoute(
      "Organisations_journalnew", 
      "Organisations/{id}/{action}", 
      new { controller = "Manage" } 
     ); 

     context.MapRoute(
      "Organisations_recent", 
      "Organisations/{action}", 
      new { controller = "Manage", action = "Index" } 
     ); 

     context.MapRoute(
      "Organisations_default", 
      "Organisations/{controller}/{action}/{id}", 
      new { controller = "Manage", action = "Index", id = UrlParameter.Optional } 
     ); 


    } 

답변

1

실제로는 꽤 쉽습니다. Url.Action에서 너무처럼, 빈 area 값을 추가

@Url.Action("Index", "Home", new { area = "" }) 

링크를 구문 분석에서, MVC는 대상 지역에없는 것을 인식하고, 링크를 생성 할 수있는 영역 경로를 사용하지 않습니다.

+0

대우를 받으면, 때로는 단순합니다! 감사. – Paul

0

경로입니다 컨트롤러/액션이 작동하려면, 그리고 그것을 다른 ro 위에 놓습니다. utes (다른 경로가 적중하지 않을 정도로 구체적이지 않은 경우).

코드를 통해이 점을 알려 드리게되어 기쁩니다. 그러나 현재 경로 테이블과 문제의 컨트롤러를 확인해야합니다.

+0

조지. 경로가 위에 추가됩니다. 지금은 각 영역에 대해 매우 불쾌한 방법으로 작업을 포함하고 RedirectPermanent ("~/Columns/UserColumnList")를 반환합니다. – Paul