我正在尝试将 json 用于我的网页的全球化选项。我喜欢通过使用一个小下拉框而不刷新整个页面来更改表单的标签,更有趣的部分是我的视图中有两个以上的表单.
到目前为止,我已经这样做了:
我的杰森:
public JsonResult Globalx(String incoming)
{
System.Globalization.CultureInfo Cult = new System.Globalization.CultureInfo(incoming, true);
System.Threading.Thread.CurrentThread.CurrentCulture = Cult;
System.Threading.Thread.CurrentThread.CurrentUICulture = Cult;
Resources.Global.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;
Global.ResourceManager.GetResourceSet(Cult, false, true);
ViewData["Name"] = Global.Name;
ViewData["Surname"] = Global.Surname;
ViewData["Birth"] = Global.Birth;
String lnginfo = Resources.Global.Culture.TwoLetterISOLanguageName.ToString();
ViewData["Languages"] = new SelectList(myList, "Value", "Text", lnginfo);
return Json(ViewData, JsonRequestBehavior.AllowGet);
}
我的观点:
@model MyCustomers.Models.Customers
@{
ViewBag.Title = ViewData["NewCustomer"];
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript" language="javascript">
$(document).ready(function () {
function changeLang() {
var lang = $("#LanguageBox").val();
$.getJSON('@Url.Content("~/Home/People/")', { incoming: lang }, function (data) {
// what should i do here to get my label's language changed?
})
}
}
</script>
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data", id = "LanguageForm" }))
{
<fieldset>
<legend>@ViewData["LanguagesTitle"]</legend>
@Html.DropDownListFor(x => x.SelectedLanguage, (SelectList)ViewData["Languages"], new { onchange = "changeLang()", id = "LanguageBox" })
</fieldset>
}
@using (Html.BeginForm("PeopleForm", "Home", FormMethod.Post, new { enctype = "multipart/form-data", id = "PeopleForm" }))
{
<fieldset>
<legend>@ViewData["SalesContract"]</legend>
<div>
<div class="Name">
@Html.Label(ViewData["Name"].ToString()) <!--> HERE </!-->
@Html.EditorFor(x => x.People.Name)
</div>
<div class="Surname">
@Html.Label(ViewData["Surname"].ToString()) <!--> HERE </!-->
@Html.EditorFor(x => x.People.Surname)
</div>
<div class="Birth">
@Html.Label(ViewData["Birth"].ToString()) <!--> AND HERE </!-->
@Html.EditorFor(x => x.People.Birth)
</div>
</div>
</fieldset>
}
不,我实际上并没有使用这种方法,我每次都刷新整个页面来更改标签的语言,但我的一些朋友告诉我,无需刷新也可以完成,我想到的第一件事是 Json .. 我不知道如果可能的话,我只是在尝试。任何其他想法都是受欢迎的。
我认为标题有点令人困惑,我假设我的问题在这里被理解,所以如果有人能找到更好的标题,请尝试修复它。