I have a viewmodel which is returned from a insert call on a MVC page.
It exposes properties according to the underlying model as well as some calculated properties.
Everything is fine except when I run an if (tryupdateModel(viewModel)). At which point it seems the calculated properties cause an error and it wont pass the if statement?
Is there an annotation I can put on this property to prevent it being checked in the tryupdate?
or how do i determine exactly what it is thats not allowing this to return true?
One way to prohibit updating a particular property is to use:
The other is to implement custom ModelBinder that reflects on the properties and ignores ones that should not be updated:
Then you can apply
[ScaffoldColumn(false)]to the property that is not updateable.I use this approach.
After the call to
TryUpdateModelyou can inspectModelStateproperty of the controller and find where the errors are.