c# - How can I delete items from my asp.net database -


i'm trying out asp.net , i'm stumped system.data.entity.infrastructure.dbupdateconcurrencyexception. exception occurs on line try save changes database in 'delete' action method.

here code edit method, works fine:

        public actionresult edit(int id)         {             movie movie = db.movies.find(id);             if (movie == null)             {                 return httpnotfound();             }             return view(movie);         }          [httppost]         public actionresult edit(movie movie)         {                 db.entry(movie).state = system.data.entity.entitystate.modified;                 db.savechanges();                 return redirecttoaction("index");         } 

and here code delete method not!

        public actionresult delete(int id)         {             movie movie = db.movies.find(id);             if (movie == null)             {                 return httpnotfound();             }             return view(movie);         }          [httppost]         public actionresult delete(movie movie)         {             db.movies.attach(movie);             db.movies.remove(movie);             //db.entry(movie).state = system.data.entity.entitystate.deleted;             //both outcommented line above , current method of marking deletion result in same exception on line below.             db.savechanges();             return redirecttoaction("index");         } 

    [httppost]     public actionresult delete(movie movie)     {         var dbmovie = db.movies.find(movie.id);         db.movies.remove(dbmovie);         db.savechanges();         return redirecttoaction("index");     } 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -