MVC4 edit method changes values to null if correspndong fields don't exist in the form
asp.net-mvc-4, entity-framework
Solution
You have to choices here:
1) As @KennyZ mentioned, add to `@Html.HiddenFor()` somewhere in your view, into your form:
@Html.HiddenFor(m => m.CreatedBy)
@Html.HiddenFor(m => m.createTime)
2) You can manually update that entity and leave those two properties alone:
var ent = dbctx.Entities.Find(model.ID);
ent.Prop1 = model.Prop1;
// ... also for other properties except those two property
dbctx.SaveChanges();
Problem
My table has two columns `CreatedBy` and `CreateTime`. In my view form, I don't have these fields. Now when I update a record using ASP.NET MVC4 Edit (post) method, these columns are set to null. But I want to retain the values. I know in my Edit (post) method, I can retrieve the record from the database and set these manually. But I am wondering whether I can ask Entity Framework not to change the values of these fields.