My project requires me to have a multilingual feature, so using Global.resx I have a list of English terms and in Global.fr.resx I have a list of French terms. This works perfectly. I can call in the term I require by using @Resources.Global. Whatever.
However, I now need to display these terms dynamically from the RESX file in a foreach, from values gathered from the entity framework. Any idea?
Bit more info:
The code is very simple, I’m still learning C#, I’m working in the View, so literally I have @Resources.Global.Whatever to display static terms and then I have a foreach loop:
<ul>
@foreach (var category in Model.categories)
{ <li>@category.categoryName</li> }
</ul>
Where I want @category.categoryName to be called from @Resource.Global too.
Assuming I understand you correctly, you want to retrieve items from a resource file based on a dynamic key name (i.e. something in a variable?). You could create an extension method for this, like so (obviously replacing the namespace to the namespace of your resource file):
Then for a
foreach, you could do this (assumingyourListis a list of strings):Or even just using Linq?