So I'm trying to do an update to an Entity model but it's not going as well as I'd like. I'm only trying to update a few fields in my model, but when I have the following code run, I get a SqlException complaining that there are fields (that I'm not trying to edit) that do not allow nulls. It's seeming like it's trying to create a new row in the database, instead of just updating the existing one? Not too sure what to make of it. Any help would be appreciated.
[HttpPost]
public ActionResult Budget(Proposal proposal)
{
if (ModelState.IsValid)
{
db.Proposals.Attach(proposal);
db.ObjectStateManager.ChangeObjectState(proposal, EntityState.Modified);
db.SaveChanges();
return RedirectToAction("Details", new {id = proposal.ProposalID});
}
return View(proposal);
}
Here's the SqlException that I'm getting: "System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'Ulid', table 'casurg2_dev2.dbo.Proposals'; column does not allow nulls. UPDATE fails.
The statement has been terminated."
And here's the view in question: http://pastie.org/7984222

SqlExceptiondetails. If it's trying to create a new record it's probably because you're expectingproposalto contain values - but the model binding may not have worked. Post the value of theproposalat this point.Ulidto theProposalEntity? Is it the primary key? a non-nullable foreign key? Still sounds like a model binding issue. If you put a breakpoint in this method - what are the values of the fields in question? You could post the Proposal Entity Class code - that may help too.Ulidis just a plain field, and it does not allow nulls.proposalin the code has everything at null, except the correct ID and any data I put in the right fields.