I have found the answer. I was not passing id value for Http Post action method.
As stated in this link
Exception thrown by DbContext when it was expected that SaveChanges for an entity would result in a database update but in fact no rows in the database were affected.
In my case the above statement is true because I was trying to update a row but without id no row was updated. Hence, the exception.
It can be done using a hidden input element which contains the id. The code below shows how to do it in Edit.cshtml –
@using (Html.BeginForm("Edit", "Home", FormMethod.Post,
new { @class = "form-horizontal", role = "form" }))
{
@Html.HiddenFor(m => m.ProjectID)
//Other code … … …
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…