在MVC我設置了第一次象下面這樣:如何從recource文件中獲取當前的文化字符串值?
public ActionResult Create()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
rm = new ResourceManager("Resources.Strings", System.Reflection.Assembly.Load("App_GlobalResources"));
ci = Thread.CurrentThread.CurrentCulture;
LoadString(ci);
return View();
}
點擊「法國」按鈕,我想從英語更改語言爲法語,所以我的jQuery像下面去:
$("#btnFrench").click(function() {
alert();
$.ajax({
type: "POST",
url: "@Url.Action("ToFrench", "Home")",
traditional: true,//data: {},
success: successFunc,
error: errorFunc
});
function successFunc(status) {//data,
var name = '@TempData["Name"]';
alert(name);
}
function errorFunc() {
alert("Operation Failed!");
}
});
[HttpPost]
public ActionResult ToFrench()
{
rm = new ResourceManager("Resources.Strings", System.Reflection.Assembly.Load("App_GlobalResources"));
ci = Thread.CurrentThread.CurrentCulture;
LoadString(ci);
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
LoadString(Thread.CurrentThread.CurrentCulture);
return RedirectToAction("Create");
}
因此,在下面的代碼,我不能獲取來自法國的資源文件上的法國價值觀。
private void LoadString(CultureInfo ci)
{
string naam = rm.GetString("Name", ci);
TempData["Name"] = naam;
ViewBag.Gender = rm.GetString("Gender", ci);
ViewBag.DateOfBirth = rm.GetString("DateOfBirth", ci);
ViewBag.About = rm.GetString("About", ci);
}
究竟是什麼問題?您似乎正在加載資源確定。請準確描述發生了什麼事情,以及與你想要的有什麼不同。 – Richard
在上一步代碼我描述了我的問題,我想將'Name'轉換爲法語'prénom',我在'fr.resx'資源文件中設置它。 –
請注意我要求你描述*當前的行爲及其不同之處*:你是否得到一個錯誤,沒有什麼,一些意想不到的價值? – Richard