Reputation: 383
How to retrieve value dynamically from resource file.
Resource file looks like:
pagecontent
n1 - "John"
n2 - "Mike"
n3 - "Dan"
I want to loop though viewmodel passed to the view and grab the value from item.Name.
i.e item.Name value = n1 then grab the text from resource file and display n1's value which is John.
@foreach (var item in Model)
{
<h1> @Resources.pagecontent.[??]/h1>
}
Is it possible to do that dynamically?
Viewmodel
public class CompanyNamesVM
{
public int Id { get; set; }
public string Name { get; set; }
....
}
if I loop it. Result would shown
n1
n2
n3
...
Upvotes: 0
Views: 2061
Reputation: 383
Got it working by doing this:
@Resources.pagecontent.ResourceManager.GetString(item.Name)
Upvotes: 1