2010-03-03 2 views
1

MVC 응용 프로그램에서 URL 기반 현지화 논리를 사용하고 있습니다. 그래서 기본 경로는 mysite/someControler이고 현지화 된 경로는 mysite/en-US/someControler입니다.MVC에서 문화권 변경

"en-US"는 기본값이있는 "culture"매개 변수의 값입니다.

문화권을 전환하고 URL 경로 값과 매개 변수를 모두 유지하는 일반적인 방법이 궁금합니다. 마스터 페이지

에서

If Request.Path.Contains("/en/") Then 
     ViewData("PathEs") = Request.Path.Replace("/en/", "/es/") 
     ViewData("PathPt") = Request.Path.Replace("/en/", "/pt/") 
    ElseIf Request.Path.Contains("/pt/") Then 
     ViewData("PathEn") = Request.Path.Replace("/pt/", "/en/") 
     ViewData("PathEs") = Request.Path.Replace("/pt/", "/es/") 
    Else 
     ViewData("PathEn") = Request.Path.Replace("/es/", "/en/") 
     ViewData("PathPt") = Request.Path.Replace("/es/", "/pt/") 
    End If 

: 그리고 나는 다음을 ViewData 비트를 설정 내 기본 컨트롤러에서
는 (다른 모든 컨트롤러가에서 상속) :

감사

+0

http://adamyan.blogspot.com/2010/02/aspnet-mvc-2-localization-complete.html –

답변

0

나는 간단한 일을 할
<div id="langbar"> 
    <% if not string.isnullorempty(ViewData("PathEs")) then %> 
     <a href="<%= ViewData("PathEs") %>">Español</a> 
    <% end if %> 
    <% if not string.isnullorempty(ViewData("PathEn")) then %> 
     <a href="<%= ViewData("PathEn") %>">English</a> 
    <% end if %> 
    <% if not string.isnullorempty(ViewData("PathPt")) then %> 
     <a href="<%= ViewData("PathPt") %>">Portugues</a> 
    <% end if %> 
</div> 

너무 똑똑하지 않지만 몇 가지 랭 (두 루틴을 모두 최적화 할 수 있음)을 다루는 경우 작업을 잘 수행하십시오.

관련 문제