2012-09-17 31 views
0

我在asp.net mvc中實現全球化,並且我在Global.resx文件中存儲了資源鍵/值。 現在,我需要從該global.resx文件中讀取所有這些資源值並將它們存儲在ViewBag中,以便我可以在mvc視圖中訪問ViewBag值。 我不想讀取使用Resource.getValue(鍵,文化)選項的值,因爲這將使我硬編碼代碼中的所有鍵,而是我想讀取所有的值,而不指定密鑰並將它們存儲全部在ViewBag中。在asp.net中讀取和存儲global.resx文件中的資源鍵/值對mvc

任何想法將不勝感激。

回答

0

Resources.AppResource在我的案例類持有資源。見下面的代碼:

 System.Resources.ResourceSet resourceSet = Resources.AppResource.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true); 
     foreach (System.Collections.DictionaryEntry item in resourceSet) 
     { 
      object key = item.Key; 
      object value = item.Value; 
     } 
+0

太棒了,非常感謝你。 :) –

相關問題