Is there an alternative for [Bind(Exclude = \"Id\")]
(Related Question) ?
Could I write a model binder?
As Desmond stated, I find remove very easy to use, also I've made a simple extension which can come in handy for multiple props to be ignored...
///
/// Excludes the list of model properties from model validation.
///
/// The model state dictionary which holds the state of model data being interpreted.
/// A string array of delimited string property names of the model to be excluded from the model state validation.
public static void Remove(this ModelStateDictionary ModelState, params string[] modelProperties)
{
foreach (var prop in modelProperties)
ModelState.Remove(prop);
}
You can use it like this in your action method:
ModelState.Remove(nameof(obj.ID), nameof(obj.Prop2), nameof(obj.Prop3), nameof(obj.Etc));