2012-08-17 54 views
0

我有一個資源文件的奇怪問題。奇怪,因爲它運作良好。 那麼,我有一些資源文件。我在我的asp.net mvc 3項目結構上創建了資源文件夾,並且鏡像視圖的文件夾結構。現在我有:ASP.NET MVC中的資源文件問題3

Views 
    Shared 
     _Layout.cshtml 

Resources 
    Shared 
     Layout.pt-BR.resx 
     Layout.en-US.resx 
     Layout.ko-KR.resx 

所有的資源文件被配置爲嵌入的資源,PublicResXFileCodeGenerator以及使用自定義工具命名空間「VIEWRES」。所有「.Designer.cs」文件都是空的。我記得在工作時看到一些代碼。

在我的.csproj文件,我有這些數據:

<ItemGroup> 
    <EmbeddedResource Include="Resources\Shared\Layout.en-US.resx"> 
     <SubType>Designer</SubType> 
     <Generator>PublicResXFileCodeGenerator</Generator> 
     <LastGenOutput>Layout.en-US.Designer.cs</LastGenOutput> 
     <CustomToolNamespace>ViewRes</CustomToolNamespace> 
    </EmbeddedResource> 
    <EmbeddedResource Include="Resources\Shared\Layout.ko-KR.resx"> 
     <SubType>Designer</SubType> 
     <Generator>PublicResXFileCodeGenerator</Generator> 
     <CustomToolNamespace>ViewRes</CustomToolNamespace> 
     <LastGenOutput>Layout.ko-KR.Designer.cs</LastGenOutput> 
    </EmbeddedResource> 
    <EmbeddedResource Include="Resources\Shared\Layout.pt-BR.resx"> 
     <SubType>Designer</SubType> 
     <Generator>PublicResXFileCodeGenerator</Generator> 
     <LastGenOutput>Layout.pt-BR.Designer.cs</LastGenOutput> 
     <CustomToolNamespace>ViewRes</CustomToolNamespace> 
    </EmbeddedResource> 
    </ItemGroup> 

的問題是:當我試圖訪問我的看法@ViewRes,它無法識別。我已經嘗試刪除自定義工具名稱空間,但@Resource也無法識別。在這兩種情況下,我得到了這個編譯錯誤:

Compiler Error Message: CS0103: The name 'ViewRes' does not exist in the current context 

有沒有人有任何想法? 謝謝, 聖保羅

編輯:NEW INFORMATIONS

我創建在VS2010項目的屬性菜單全球Resources.resx文件,它的工作與我已經進入自定義工具命名空間。 「資源」名稱空間仍然不起作用。我認爲問題在於本地資源文件。不幸的是,我需要它們,因爲我無法重命名全局resources.resx文件,包括文化代碼。

編輯2 我在資源文件夾中創建了新的.resx文件,我能看到的是文件名不能有2「。」。名稱是Resources.resx,它的工作原理。如果名稱爲Resource-en-US.resx,則該名稱有效,但如果名稱爲Resources.en-US.resx,則它失敗!

+0

我認爲它可以幫助你 http://stackoverflow.com/questions/886473/can-i-access-resources-file-from-a-view-in-mvc – 2012-08-17 13:54:38

+0

謝謝,亞歷克斯!但沒有:( – paulofabiano 2012-08-17 14:15:54

+0

我注意到你應該添加一個沒有兩個點的資源文件來創建命名空間 – user1080381 2014-01-15 06:41:52

回答

0

我想你也可以寫一個自定義幫助器,它會通過反射字符串來返回。

+0

是的,我可以嘗試但它有意義嗎?它是默認資源的命名約定:xxx.yy -zz.resx。 – paulofabiano 2012-08-17 15:23:18