Search code examples
c#asp.net-mvclinqupdatemodel

UpdateModel() causing row(s) to not be updated


I'm having a problem using UpdateModel(theModelToUpdate) causing concurrency issues.

Basically whats happening is, there is a row in the database that contains most but not all the information needed for that row. The rest of the needed information is NULL. The user (using a listbox) would then add information to this row, as well as creating new rows (An ajax command is sent for every item in the listbox. So the controller is being called very fast because of the loop used to get the items).

In my controller I first check to see if the columns the user will be updating are NULL. If they are, I use UpdateModel to update the row. If they are not null (meaning the row is complete ) then I create new rows with the remaining listbox items.

When debugging, I notice that since the controller is called so quickly, the UpdateModel isn't called right away like I had planned. Several items from the listbox get skipped because of this and I get an error saying the row cannot be updated.

How can I solve this?


Solution

  • I resolved the issue by not using UpdateModel to update the row. Instead I Insert the rows, then go back and delete the row with the missing information. Probably not the best solution, but it fixed my problem.