Razor MVC Multi-language 다중 언어 시스템의 실현 문제

Razor MVC Multi-language 다중 언어 시스템의 실현 문제
컨트롤, 자체 지원(예: Telerik)
Resource 파일 이름에 대한 컨트롤 요구 사항에 따라 APP 설정GlobaResource 디렉토리의 파일
웹에서.config에서 UICulture 등의 정보를 수정하면 어떤 언어의 디스플레이 설정이 완성됩니다
Globalization in MVC 3with Razor
 
주요하다
1. Form Request를 처리합니다. 이전의 ASP 모드와 같이 Submit 다음에 백엔드의ActionURL ASP 페이지를 통해 파라미터를 받고 피드백을 처리합니다.
기본 요구 사항:
1. 프론트에 Form, Submit, 제출한 내용
@{Html.BeginForm("Index","Home");}
<table cellpadding="0″cellspacing="0"
style="border:0px none white; width:600px;">
<tr>
<td
style="width:300px;">
 
<table cellspacing="0"cellpadding="0"
style="border:0px none white; width:300px;">
<tr>
<td
style="width:150px;text-align:left;">Language</td>
<td
style="width:150px;text-align:right;">
<input
type="submit"
value="Update Language"
/>

….
@{Html.EndForm();}
 
2. 백그라운드 컨트롤러 Controller
Form의 Html에 해당하는 Action 1개BeginForm("Index","Home")
 public ActionResult Index(String language)
        { …}
3.         ,  page_load
          、             :
    (   Namespace   Customtoolnamespace)
<td style="width:300px;">@HWResources.ServerSide.HelloString</td>
    :(     )

 
3. View Access of Local Resource using Html Extension Method
HTML help 확장을 통해 로컬 리소스에 액세스
Razor는 기존의 웹 폼 뷰 엔진과 달리 웹 폼에서 코드로 자원에 접근할 수 있습니다.HTML 확장을 통해 GetLocalResourceObject와 같은 방식으로 호출하는 방법에 대해 설명합니다.
 
    page.ViewContext.HttpContext.GetLocalResourceObject
 
     HTMLHelper   :
1.       html helper    
2.    Razor viewEngine configuration entry,  web.config, 
<System.Web.WebPages.Razor> 
      view\web.config

 
이 방법의 전체적인 단계는 다음과 같다.
1. Extension, 첫 번째 인자, 그리고 LocaresourceObject의 사용을 확인하는 것은 APPLocalResources 디렉토리
public static string LocalResources(this WebViewPage page, string key)
        {
            //        ,      string  
            return page.ViewContext.HttpContext.GetLocalResourceObject(page.VirtualPath, key) as string;}

 
2. Razor view 코드
<b>View Access of custom embedded resource using html extension</b></td>
<td style="width:300px;">@this.LocalResources("String1")</td>
 
LocalResources(this WebViewPage page=@this, string key= String1)

4. 상기 코드의 간략한 버전이지만 너무 많은 코드를 초래했다.
<b>View Access of Local Resource using Http Context GetLocalResourceObject ....</b></td>
<td style="width:300px;">@HttpContext.GetLocalResourceObject("~/Views/Home/Index.cshtml","String1")</td>

 
매개변수에는 현재 View 페이지가 필요합니다."~/Views/Home/Index.cshtml"
마지막 효과:

좋은 웹페이지 즐겨찾기