I'm new to c sharp. I"ve got an ASP.NET 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.