ASP.NET MVC & Detached Entity won't save

Posted by Justin on Stack Overflow See other posts from Stack Overflow or by Justin
Published on 2010-06-10T00:08:33Z Indexed on 2010/06/10 0:12 UTC
Read the original article Hit count: 509

Filed under:
|

Hey all,

I have an ASP.NET MVC POST action for saving an entity on submit of a form. It works fine for insert but doesn't work for update, the database doesn't get called, so it's clearly not tracking the changes, as it's "detached". I'm using Entity Framework w/.NET 4:

//POST: /Developers/Save/
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Save(Developer developer)
        {
            developer.UpdateDate = DateTime.Now;
            if (developer.DeveloperID == 0)
            {//inserting new developer.
                DataContext.DeveloperData.Insert(developer);
            }
            //save changes - TODO: doesn't update...
            DataContext.SaveChanges();
            //redirect to developer list.
            return RedirectToAction("Index");
        }

Any ideas would be greatly appreciated, thanks,

Justin

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc