0

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?

Aqua
  • 127
  • 1
  • 13

1 Answers1

2

Try this:

text = new ResourcesTexts();
text.myList = new List<string>();

OR

Create list in ResourcesTexts constructor

webdeveloper
  • 17,174
  • 3
  • 48
  • 47
  • yes thanks. but the retrieved values are not in order. How can i order the items of the list using LINQ. – Aqua Oct 30 '12 at 13:51
  • [Here](http://stackoverflow.com/questions/188141/c-sharp-list-orderby-alphabetical-order) you have another answer that can help you solve this. – msancho Oct 30 '12 at 13:59