Reputation: 127
I have the following code in my MVC3 homecontroller's Index method. What I am trying is, getting values from my Resource File (.resx) and show them in a view.
private ResourceManager rm = null;
private ResourcesTexts text;
public ActionResult Index()
{
text = new ResourcesTexts();
rm = new ResourceManager("Credit.SiteResources", Assembly.GetExecutingAssembly());
var res = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry resource in res)
{
if (resource.Key.ToString().Count() == 14)
{
string x = resource.Value.ToString();
text.myList.Add(x);
}
}
return View(text);
}
i am getting null reference error while debugging.
Any Help?
In my view I am trying something like this.
@foreach(var x in Model.myList.Item)
{
<p>@x</p>
}
How do I solve it?
Upvotes: 0
Views: 99
Reputation: 17288
Try this:
text = new ResourcesTexts();
text.myList = new List<string>();
OR
Create list in ResourcesTexts
constructor
Upvotes: 2