2012-11-14 5 views
0

나는 조금 이상한 행동을하는 경로를 모델링해야합니다. 그들이 무엇을하고 싶은지는 다음과 같습니다.ASP.NET MVC 3에서이 경로를 어떻게 모델링 할 수 있습니까?

/AssetManagement -> Asset Landing page 
/AssetManagement/Add -> Add an asset 
/AssetManagement/Edit -> Edit an asset 
/AssetManagement/Locations -> Locations landing page 
/AssetManagement/Locations/Add -> Add a location 
/AssetManagement/Locations/Edit -> Edit a location 

확실하지 않지만 두 컨트롤러로 모델링해야한다고 생각합니다. AssetsController 및 LocationsController. I의 의견이 존중보기 폴더 아래에있는 것/편집/인덱스를 추가하고 아마 두 개의 경로가 정의한 것이라고 생각 :

routes.MapRoute(
    "AssetManagement", // Route name 
    "AssetManagement/{action}/{id}", // URL with parameters 
    new { controller = "Assets", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
    new[] { "MyApplication.Web.Website.Controllers" } 
); 

routes.MapRoute(
    "AssetManagementLocations", // Route name 
    "AssetManagement/{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Locations", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
    new[] { "MyApplication.Web.Website.Controllers" } 
); 

는 그냥 나에게 잘못을 조금 느낀다. 물건을 다룰 때 모범 사례가 누락 되었습니까? 이것이 어떤 종류의 문제를 일으킬 수 있습니까? 그들이 원하는 시스템이 이렇게 많이 만들어집니다.

// 편집 이런 질문을하는 것이 좋지 않은 곳이라면 어디에서 물어야합니까?

+0

는 "그것은 조금을 느끼는 이유에 대해 생각을 고려 방법 나에게 잘못 "하고 더 많은 정보가 질문에 추가되어야하는지 확인하십시오. ... 당신이 어떤 느낌을 주든간에 (한 컨트롤러에서 모든 것과 같이, 모든 영역에서 ...) 라우팅을 설정할 수 있기 때문에 왜이 것이 좋지 않은지 이해하지 않고 더 나은 경로를 제안하십시오. –

답변

1

지역을 만들 수 있습니다.

영역에서 자산과 위치에 대해 2 개의 컨트롤러를 만듭니다.

위험 할 수있는 경로로 재생하는 대신 MVC 개념으로 재생하십시오.

지정한 두 번째 경로는 영역과 밀접하게 관련됩니다. 영역을 만들면 경로가 자동으로 만들어집니다. 도움이되기를 바랍니다.

Area - AssetManagement 
    Controller1 - HomeController 
       Action1 - Add 
       Action2 - Delete 

    Controller2 - LocationsController 
       Action1 - Add 
       Action2 - Delete 

routes.MapRoute(
    "AssetManagementLocations", // Route name 
    "{Area}/{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Locations", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
    new[] { "MyApplication.Web.Website.Controllers" } 
); 
1

해당 프로젝트를 확인하십시오. 당신은 MVC에 설치 경로가지도하는이 정확하게의 명확한 의도에 이르게 경로 생성하여 액션 메소드 또는 컨트롤러를 장식 Nuget 수있는 컨트롤러/

https://github.com/mccalltd/AttributeRouting/wiki/2.-Usage

관련 문제