I think I almost have this working, but I cant figure out how to finish.
Model:
public class Location
{
public int LocationId { get; set; }
public string SiteCode { get; set; }
public int PersonId { get; set; }
public int IncidentId { get; set; }
}
View Model
public List<Location> LocationList { get; set; }
Controller:
[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();
}
The line db.Location.AddObject(location); is receiving empty. How do I get the location list from the foreach, to the db?
[HttpPost]? Also, what'sTrespassEntitiessupposed to be?