2009-12-06 5 views
0

나는 많은 글을 읽었고, 나는 그 미스터리를 보지 못했다.Routes MVC Problem

신체가 나를 도와 줄 수 있습니까?

내가 처럼 직접 URL을 호출하려고하면 내가 URL을

http://localhost:8458/Account/EditProfile?username=cboivin

있어

<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %> 

사용하면 내 Global.asax에

public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");     
      routes.MapRoute(
       "Default",            // Route name 
       "{controller}/{action}/{id}",       // URL with parameters 
       new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
      ); 
      routes.MapRoute("UserName", "Account/{action}/{username}", 
      new { action = "EditProfile", controller = "Account" }); 

     } 

     protected void Application_Start() 
     { 
      RegisterRoutes(RouteTable.Routes); 
     } 

있다 http://localhost:8458/Account/EditProfile/cboivin

에 작동하지 ...

내 방법 내 AccountController 나는 내 실수입니다 잘 모릅니다

public ActionResult EditProfile(string username) 
     { 

      return View(ServiceFactory.UserAccount.GetUserByUserName(new GetUserByUserNameArgs(username))); 
     } 

에 있습니다. 어떤 시체가 나를 도울 수 있습니까? 감사.

답변

6

경로를 위에서 아래로 읽으면 "모든 경로를 잡습니다"일반 경로가 마지막에 있어야합니다. 보다 구체적인 경로가 상단에 와야하는 동안,

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

을 그리고 당신의 라우팅 테이블의 맨 아래에 있어야 더 일반적인 경로를 기억

routes.MapRoute("UserName", "Account/{action}/{username}", 
      new { action = "EditProfile", controller = "Account" }); 


routes.MapRoute(
      "Default",            // Route name 
      "{controller}/{action}/{id}",       // URL with parameters 
      new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
     ); 
0

제거하십시오.