Q:

Populate a List <> not a Select List

I'm new to c sharp.   I"ve got a MVC Core 2.0 project and I need to populate a list inside a model and return that model to the page.   My model looks like this:
public class PageModel
     public string Title {get; set;}
     public List<ChartGroups> Chart { get; set; }    

}

public class ChartGroups
{
    public string Freq { get; set; }    
    public string Head { get; set; }
}

To populate this I've got the following:
public PageModel GetChart(){
 PageModel R = new PageModel(); 

 R.Title = "Some Title";
 R.Chart. Add(New ChartGroups {Freq ="Test", Head="Test2"});
 R.Chart. Add(New ChartGroups {Freq ="Test3", Head="Test4"});
 return(R);
}

The problem is I get an error saying I need to obstinate the object when I get to the R.Chart. Add... line.   I've been doing this with drop down list and it works just fine....I'm sure I'm missing something simple just can't see it. 
UPDATE:
I know that I need to obstinate the object, just not sure how to do so under this context.   
Thanks! 

A:

You need to create an instance of the List<ChartGroups>() before you can start adding items to it.  You can either do this in your GetChart() method:
public PageModel GetChart()
{
    PageModel R = new PageModel();

    R.Title = "Some Title";
    R.Chart = new List<ChartGroups>(); //< ---
    R.Chart. Add(New ChartGroups { Freq = "Test", Head = "Test2"});
    R.Chart. Add(New ChartGroups { Freq = "Test3", Head = "Test4"});
    return R;
}

Or in your PageModel class:
public class PageModel
{
    public string Title { get; set; }
    public List<ChartGroups> Chart { get; set; } = new List<ChartGroups>();
}

