2012-09-03 3 views
0

매개 변수 집합을 MVC3 컨트롤러에 라우팅하는 방법이 있습니까?ASP.NET MVC3 컨트롤러 메서드 경로 변수 매개 변수

나는

public ActionResult myaction(string f1, string f2, string f3, string f4) 
{ 
} 

및 경로

routes.MapRoute("brittleroute", 
      "myaction/{f1}/{f2}/{f3}/{f4}", 
      new { controller = "mycontroller", action = "myaction", f1 = UrlParameter.Optional, f2=UrlParameter.Optional, f3=UrlParameter.Optional, f4=UrlParameter.Optional } 
      ); 

하지만 그것을 날조하고있어 순간에

/myaction/foo 
or 
/myaction/foo/bar/widget/.../foo1/foo2/ - i.e. of unknown length. 

같은 URL에 맞게 뭔가를 얻으려고 그것은 끔찍하게 부서지기 쉽습니다.

파고 및 일부 오프라인 도움이 후

답변

1

...

public ActionResult myaction(string allsegments) 
{ 
    var urlsegments = allsegments.split('/'); 
    //... 
} 


routes.MapRoute("betterroute", 
     "myaction/{*allsegments}", 
     new { controller = "mycontroller", action = "myaction"} 
     );