This project is read-only.

Part 6 - Problem with Bind-attribute

Oct 15, 2013 at 2:05 PM
Edited Oct 15, 2013 at 2:21 PM
When I've added Bind-attribute [Bind(Exclude = "AlbumId")]
I've faced with a trouble during execution of "Edit" - action
I've got next error:
"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."

Source Error:
Line 80: {
Line 81: db.Entry(album).State = EntityState.Modified;
Line 82: db.SaveChanges(); //this line causes an error
Line 83: return RedirectToAction("Index");
Line 84: }

How could you solve it? Without this attribute everything is fine.
Nov 5, 2013 at 9:26 PM
Edited Nov 5, 2013 at 9:27 PM
Set a breakpoint and view the 'album' object being passed to the HTTP POST 'Edit' in the 'MVCSTOREMANAGERCONTROLLER'
If the ID = 0 it means you are trying to update a row with a key value that did not get set correctly.
If the above is true have to figure out how to insure that the view reference the ID so that it is there to get pulled and returned to the controller.
Marked as answer by hiderline on 11/5/2013 at 1:39 PM