I have a simple MVC4 model that adds a DateTime.Now list to List<DateTime>() .
However, when I do EntityState.Modified , the changes are not saved. I debugged this by changing another property in the model and keeping everything in order.
Therefore, I really do not understand why this does not save. If anyone has ideas on why this is not a salvation, it will be a salvage material:
Model:
public class Page { public int Id { get; set; } public string PageURL { get; set; } public string Name { get; set; } public string Title { get; set; } public List<DateTime> Visits { get; set; } public Page() { Visits = new List<DateTime>(); } }
Here is my code:
private ApplicationDbContext db = new ApplicationDbContext(); public ActionResult CookiePolicy() { var page = db.Pages.FirstOrDefault(c => c.PageURL == "cookiepolicy"); page.Visits.Add(DateTime.Now); // this list of datetime objects does not get updated page.Title = "test "; //but this property does ViewBag.Title = page.Title; db.Entry(page).State = EntityState.Modified; db.SaveChanges(); return View(page); }
source share