2

나는 다음과 같은 경로를 만들어 :MVC3지도 노선 문제

routes.MapRoute(
    "TestRoute4", // Route name 
    "Report {ref_id} Test Board", // URL with parameters 
    new { controller = "stats", action = "index" } // Parameter defaults 
); 

public ActionResult index(string ref_id) 
{ 
} 

이 잘 작동하지만 지금 내 컨트롤러는이 보고서 25 테스트 보드를 일치하는 경로에서 호출 된 것 알고 것처럼. MapRoute에서 컨트롤러에 다른 것을 전달할 수있는 방법이 있습니까? 나는 심지어 하드 코딩을 신경 쓰지 않는다. 보고서 및 테스트 보드라는 단어를 전달하기 만하면됩니다. 이 작업을 수행 할 수있는 컨트롤러에서

Route route = routes.MapRoute(
    "TestRoute4", // Route name 
    "Report {ref_id} Test Board", // URL with parameters 
    new { controller = "stats", action = "index" } // Parameter defaults 
); 

route.DataTokens["YourKey"] = "your value"; 

:

맨디에게, 당신이 도움이 될 수 있습니다

답변

3

사용 DataTokens 희망

public ActionResult Index() { 

    // check if matched route is TestRoute4 (optional) 
    if (this.RouteData.Route == RouteTable.Routes["TestRoute4"]) { 
     // do something 

     var val = this.RouteData.DataTokens["YourKey"]; 
    } 

}