2011-08-24 6 views
0

라우트 :간단한 Html.Actionlink 질문 (MVC3)

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

Html 헬퍼 :

@Html.ActionLink("Chairs", "List", "Item", new {id="Chairs"}, null) 

가 생성 링크 : 나는 그것을 보여

http://localhost:57899/Item/List?id=Chairs 

원하는 것은 :

http://localhost:57899/Item/List/Chairs 

어떻게 수행하나요?

+0

'ItemController'의'List' 액션의 서명은 무엇입니까? –

+0

@David 서명? public ActionResult List (문자열 id) { return 뷰 (_repository.GetItems (id)); }' –

답변

0

ActionLink를 사용하는 대신 다음을 시도하면 어떻게됩니까?

@Html.RouteLink("Items", new { id = "Chairs" }) 
0

당신은 Html.RouteLink (하지 작업 링크)를 호출하고이처럼 일반에 따라 추가 경로를 매핑 : 당신은 RouteLink를 호출 할 때

routes.MapRoute(
     "ChairsRoute", // Route name 
     "Item/List/{id}", // URL with parameters 
     new {controller = "Item", action = "Index", id = UrlParameter.Optional} // Parameter defaults 
     ); 

, 당신은 단순히 "ChairsRoute"이름을 전달합니다