2012-05-25 4 views
7

Stack을 검색하여 MSDN 문서를 읽고 Bing을 사용했지만 왜 작동하지 않는지 알 수 없습니다. 아래에 관련 코드가 있습니다. Browse이라는 경로는 정상적으로 작동하지만 Details 경로의 productCode 매개 변수는 항상 아무 것도 아닙니다. 개조를하면 404 페이지의 리소스를 찾을 수 없습니다.ASP.NET MVC4 라우팅 문제

' Lives in controller called 'Details' 
' Usage: site.com/details/abc123 
Function Index(productCode As String) As ActionResult 

' Lives in controller called 'Browse'  
' Usage: site.com/browse/scifi/2 
Function Index(genre As String, Optional page As Integer = 1) As ActionResult 

라우트는 다음과 같습니다 당신의 경로를 정의 할 때

routes.MapRoute(_ 
     "Browse", _ 
     "{controller}/{genre}/{page}", _ 
     New With {.controller = "Browse", .action = "Index", .id = UrlParameter.Optional, .page = UrlParameter.Optional} 
    ) 

    routes.MapRoute(_ 
     "Details", _ 
     "details/{productCode}", _ 
     New With {.controller = "Details", .action = "Info", .productCode = UrlParameter.Optional} 
    ) 

답변

7

순서는 중요하지 않습니다.

site.com/details/abc123를 요청하면 처음 경로와 일치한다고 생각합니다.

당신은 당신의 제품 코드가 null 인 이유

controller = "details"

action = "Index"

genre = "abc123"

을 얻을 것이다.

route.MapRoute 문을 전환하면 문제가 해결됩니다.

두 번째 경로가 index이 아닌 info으로 설정되어 있지만 그게 오타라고 가정합니다.