2012-06-13 2 views
0

이 라우트 맵을 정의했습니다.Asp.net mvc3에서 다른 경로 추가가 작동하지 않습니다.

routes.MapRoute("default", // route name 
      "{controller}/{action}/{id}", // url with parameters 
      new { controller = "home", action = "index", id = UrlParameter.Optional }, // parameter defaults 
      new string[] { "mobilesurveys.mt.controllers" } 
     ); 

완벽하게 작동합니다. 이제 다른 routemap을 추가하고 싶습니다.

routes.MapRoute("couponreedem", // route name 
      "{controller}/{action}/{clientname}", // url with parameters 
      new { controller = "Rc", action = "index", id = UrlParameter.Optional }, // parameter defaults 
      new string[] { "mobilesurveys.mt.controllers" } 
     ); 

이렇게 정의했습니다. 여기 Rc가 제 컨트롤러입니다. 나는 항상 null가됩니다

public ActionResult Rc(string clientname) 
    { 

     viewModel =dataRc.ProductCategoryGet(); 
     return View(viewModel); 
    } 

CLIENTNAME로 정의 컨트롤러에서 .COM/Rc를/Rc를/새미

과 방법으로 URL을 제공하고 있습니다. 기존 경로가 방해받지 않는 동안 다른 경로를 추가하는 방법.

감사합니다.

+1

, 당신의 경로 모두가 동일한 것 같다? –

+0

"id"대신 "clientname"으로 매개 변수를 사용하지 않는 한 - "id"를 붙이면 두 번째 경로 (couponreedem)를 정의 할 필요가 없습니다. 그렇지 않으면 두 번째 경로 맵 (couponreedem)에서 매개 변수를 수정하십시오. "id = Url.Paremeter.Optional"을 "clientname = Url.Paremeter.Optional"로 변경하십시오. 또한, "Areas"를 사용하지 않는다면 컨트롤러에 대한 네임 스페이스를 지정할 필요가 없습니다. – anAgent

답변

1

실제로는 동일하게 보입니다. 그러나 새로운 것을 원할 경우, 이와 같은 것을 시도해 볼 수 있습니다. 기본 설정보다 높을 수 있습니다.

routes.MapRoute("couponreedem", // route name 
      "RC/{action}/{clientname}", // url with parameters 
      new { controller = "Rc", action = "index", clientname = UrlParameter.Optional }, // parameter defaults 
      new string[] { "mobilesurveys.mt.controllers" } 
     ); 
RC와 경로를 수정합니다

/... 또한 액션이 인덱스 이름을 지정해야합니다 당신이 두 번째 필요 왜

public ActionResult Index (string clientname) 
    { 

     viewModel =dataRc.ProductCategoryGet(); 
     return View(viewModel); 
    } 
관련 문제