title: C# Instance of Lists In Data Model
body: <p>I've not been able to find an answer so am posting this. If this has already been answered then please point me in that direction.</p>
  
  <p>I have a class model in MVC as below:</p>
  
  <pre><code>public class SearchModel
  {
      public int id { get; set; }
      public string ActivityName { get; set; }
      public string Subject { get; set; }
      public string Level { get; set; }      
      public List&lt;LocationModel&gt; Locations { get; set; }
  }
  
  public class LocationModel
  {
      public int LocationID {get; set;}
      public string Location { get; set; }
  }
  </code></pre>
  
  <p>I am trying to populate the Locations list in my code but can't seem to get the code to create an instance of it properly. </p>
  
  <p>I have a List of SearchModel as there are multiple items. This is populating fine by doing the following:</p>
  
  <pre><code>List&lt;SearchModel&gt; items = new List&lt;SearchModel&gt;();
  </code></pre>
  
  <p>and then looping through the following to populate the model.</p>
  
  <pre><code>SearchModel item = new SearchModel();
  item.ActivityName = reader["ActivityName"].ToString();
  item.Level = reader["LevelNames"].ToString();
  item.Subject = reader["SubjectNames"].ToString();
  item.id = Convert.ToInt32(reader["ActivityID"]);
  items.Add(item);
  </code></pre>
  
  <p>How do I add the data to the Locations List in the SearchModel? This will contain multiple records also.</p>