This is a somewhat old question, but I do not believe that it was answered properly. Manipulating a binding does not change the manipulation process at all, since the check is performed before / at the same time as the binding. As in the above example, marking the property as excluded will still generate the false property modelstate.isvalid.
The most recommended way to validate is to create dedicated ViewModels, as it takes care of several other issues in the same way that you may or may not know about.
An alternative to ViewModels is to control the modelstate object to get the selection (or exclude) of the property to check as follows:
(there is additional code for deleting magic strings here)
var modelPropAsString = nameof(yourmodel)+"."+nameof(yourmodel.Id); if (ModelState[modelPropAsString ].Errors.SingleOrDefault() != null) { ModelState[modelPropAsString ].Errors.Clear(); yourmodel.Id = 0; }
The above excludes the Id property from validation. You can rotate the Id property authentication code if you want.
source share