基本信息
源码名称:mvc多国语言网站解决方案 MvcResourceLang
源码大小:8.22M
文件格式:.rar
开发语言:C#
更新时间:2015-02-25
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
代码:
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading; using System.Web; using System.Web.Mvc; namespace MvcResourceLang.Models { public static class LangHelper { //界面普通文字的多语言 public static string GetLangbyKey(this HtmlHelper htmlhelper, string key) { Type resourceType = (Thread.CurrentThread.CurrentUICulture.Name == "en-US") ? typeof(Resources.en_US) : typeof(Resources.zh_CN); PropertyInfo p = resourceType.GetProperty(key); if (p != null) return p.GetValue(null, null).ToString(); else return "undefined"; } //js定义多语言弹出框 public static string LangOutJsVar(this HtmlHelper htmlhelper, string key) { Type resourceType = (Thread.CurrentThread.CurrentUICulture.Name == "en-US") ? typeof(Resources.en_US) : typeof(Resources.zh_CN); PropertyInfo p = resourceType.GetProperty(key); if (p != null) return string.Format("var {0} = '{1}'", key, p.GetValue(null, null).ToString()); else return string.Format("var {0} = '{1}'", key, "undefined"); } } }
前台:
<body> <div> @{ string controller = ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString(); string action = ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(); //string lang = ViewContext.Controller.ValueProvider.GetValue("lang").RawValue.ToString(); } @Html.ActionLink("中文", action, new { Controller = controller, lang = "zh-CN" }, new { @class = "btn-a" }) @Html.ActionLink("English", action, new { Controller = controller, lang = "en-US" }, new { @class = "btn-a" }) </div> <h2>@Html.GetLangbyKey("LogonDisplay")</h2> <div class="logon-div"> @using (Html.BeginForm()) { <table> <tr> <td>@Html.LabelFor(m => m.UserName)</td> <td>@Html.TextBoxFor(m => m.UserName, new { style = "width:100%" })</td> </tr> <tr> <td>@Html.LabelFor(m => m.Pwd)</td> <td>@Html.PasswordFor(m => m.Pwd, new { style = "width:100%" })</td> </tr> <tr> <td colspan="2">@Html.CheckBoxFor(m => m.Rememberme) @Html.LabelFor(m => m.Rememberme) <input type="submit" value="@Html.GetLangbyKey("LogonDisplay")" style="float:right;"/> </tr> <tr style="font-size: 12px;"> <td colspan="2"> @Html.GetLangbyKey("NoteDisplay") @Html.ActionLink(Html.GetLangbyKey("RegisterDisplay"), "Register", null, null) . </tr> </table> } </div> </body>