I\'ve been looking for a proper way to mark a property to NOT be changed when updating a model in MVC.
For example, let\'s take this small model:
cla
I guess you don't want the property to be changed just in some cases, because if you are not going to use it never in your application, just remove it from your model.
In case you want to use it just in some scenarios and avoid its "nullification" in the case above, you can try to:
Hide the parameter in the view with HiddenFor:
@Html.HiddenFor(m => m.Token)
This will make your original value to be kept unmodified and passed back to the controller.
TryUpdateModel
: http://msdn.microsoft.com/en-us/library/dd460189(v=vs.108).aspxLoad again your object in the controller from your DBSet
and run this method. You can specify both a white list and a blacklist of parameters that shall or shall not be update.