title: Saving a list of entities to the db - MVC
body: <p>I think I almost have this working, but I cant figure out how to finish.</p>
  
  <p>Model:</p>
  
  <pre><code> public class Location
   {
      public int LocationId { get; set; }
      public string SiteCode { get; set; }
      public int PersonId { get; set; }
      public int IncidentId { get; set; }
    }
  </code></pre>
  
  <p>View Model</p>
  
  <pre><code>    public List&lt;Location&gt; LocationList { get; set; }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult AddRecord(RecordViewModel model)
      {
          if (ModelState.IsValid)
          {
              Location location;
              foreach (var loc in model.LocationList)
              {
                  location = new Location
                  {
                      PersonId = model.PersonId,
                      SiteCode = loc.SiteCode,
                      IncidentId = loc.IncidentId
                  };
              }
  
              using (var db = new MyEntities())
              {
                  db.Order.AddObject(incident);
                  db.Location.AddObject(location);
                  db.Comment.AddObject(comment);
  
                  db.SaveChanges();
              }
  </code></pre>
  
  <p>The line <code>db.Location.AddObject(location);</code> is receiving empty.  How do I get the location list from the foreach, to the db?</p>