What is the best way to maintain an entity's original properties when they are not included in MVC binding from edit page?

Posted by kingdango on Stack Overflow See other posts from Stack Overflow or by kingdango
Published on 2011-11-16T01:45:57Z Indexed on 2011/11/16 1:51 UTC
Read the original article Hit count: 190

I have an ASP.NET MVC view for editing a model object. The edit page includes most of the properties of my object but not all of them -- specifically it does not include CreatedOn and CreatedBy fields since those are set upon creation (in my service layer) and shouldn't change in the future.

Unless I include these properties as hidden fields they will not be picked up during Binding and are unavailable when I save the modified object in my EF 4 DB Context. In actuality, upon save the original values would be overwritten by nulls (or some type-specific default).

I don't want to drop these in as hidden fields because it is a waste of bytes and I don't want those values exposed to potential manipulation.

Is there a "first class" way to handle this situation? Is it possible to specify a EF Model property is to be ignored unless explicitly set?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about entity-framework