ASP MVC 3 프로젝트에서 언어 전환을 사용하려고합니다.ActionLink를 사용하여 ASP MVC 3 스위칭 언어
라우팅는 다음과 같이 정의된다 :
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"DefaultWithLanguage", // Route name
"{language}/{controller}/{id}/{slug}", // URL with parameters
new { language = "en", controller = "Front", action = "Details", id = UrlParameter.Optional, slug = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
이 (_Layout.cshtml에서) 언어를 전환하는 시도는 다음과 같이 작동
<li>@Html.ActionLink("Spanish", ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { language = "es" })</li>
대신에 (다음과 같이 URL을 얻기의 가진 후 선택 스페인어)
.../es/ControllerName/ActionName
은 내가 '이 점점 M :
내가 다음 (알 마지막 널 매개 변수)에 ActionLink 설정하면.../ControllerName/ActionName?Length=11
:
이.../ControllerName/ActionName?language=es
내가 무엇을 놓치고 :
<li>@Html.ActionLink("Spanish", ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { language = "es" }, null)</li>
을 나는이 얻을? 미리 감사드립니다.
기본 경로도 그대로 두셨습니까? 모든 경로 등록을 표시하십시오. –
@Darin (변경된) 공식을 살펴보십시오. RegisterRoutes에 모든 코드를 포함 시켰습니다. –