【发布时间】:2017-08-24 15:26:12
【问题描述】:
我创建了一个应用程序,我需要在下拉选择中更改文化。
这是我的操作方法代码。
public ActionResult SetCulture(string lang)
{
if (lang == "en")
return RedirectToAction("Index");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(lang.Trim()); //.TextInfo.IsRightToLeft;
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang.Trim());
List<Agent> lstMainAgent = new List<Agent>();
List<Agent> lstAgent = db.Agents.ToList();
for (int i = 0; i < lstAgent.Count(); i++)
{
lstAgent[i].AddressCity = Resources.Resource.AddressCity;
lstAgent[i].AddressCountry = Resources.Resource.AddressCountry;
lstAgent[i].AddressPostcode =Resources.Resource.AddressPostcode;
lstAgent[i].AddressStreet = Resources.Resource.AddressStreet;
lstAgent[i].Name = Resources.Resource.Name;
lstAgent[i].PhoneNumber = Resources.Resource.PhoneNumber;
lstMainAgent.Add(lstAgent[i]);
}
return View("Index", lstMainAgent);
}
这似乎有效,但我有动态值列表,其值未添加到资源文件中,并且我在视图中获得空白属性值。我需要打印视图中的所有值。我怎样才能做到这一点?
提前致谢
【问题讨论】:
-
我不太明白你想在 for 循环中做什么。你能详细说明一下吗?
-
我不确定我的代码是否正确。使用 for 循环我想将资源值传递给列表中的视图?对吗?
-
您可以访问视图中的资源。你不需要这个 for 循环。像这样访问
@Resources.Resource.AddressCountry
标签: asp.net-mvc localization globalization