I ran into this and it was caused by the entity's ID (key) field not being set. Thus when the context went to save the data, it could not find an ID = 0. Be sure to place a break point in your update statement and verify that the entity's ID has been set.
From Paul Bellora's comment
I had this exact issue, caused by forgetting to include the hidden ID
input in the .cshtml edit page
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…