DefaultModelBinder exposes a public method:
DefaultModelBinder.BindModel, and a number of protected method available for overriding. All of them listed here.
Besides the model, these method refer to properties only, not fields, like
- GetModelProperties,
- GetFilteredModelProperties,
- GetPropertyValue,
- OnXYZValidating,
- OnXYZValidated,
- OnXYZUpdating,
- OnXYZUpdated,
- GetXYZValue,
where XYZ
stands for either Model,
or Property/ies,
or both, and so on.
As you can see there is no Fields
mentioned with these names whatsoever. As Darin explained no direct changes to Model's state are tolerated by the Binder. Hence no Field
in its methods.
And also, you may wish to take a look at another important class: ModelBindingContext. An instance of this class gets passed to the BindModel,
and subsequently to BindSimpleModel,
and BindComplexModel,
depending on model type (string, int,
... are considered simple, everything else is complex).
So, this context has the following properties:
- ModelXYZ, and
- PropertyXYZ.
In other words you have no means to reference the fields in your ViewModel unless you do not override these classes and undertake special actions to do so.
But again, beware of fighting the framework, its always easier to follow it instead.
EDIT: The ModelMetadata class holds all the data needed to bind the model. Its code however, shows no sign of fields, field names, etc. Only properties are referenced and accessed. So, even if you try to inherit and override DefaultModelBinder and ModelBinderContext, you still won't be able to access fiellds, nevermind what their access modifier is: public, private, etc.
Hope this explains most of it.
private
. Viewmodel classes are normally just datacontainers and mostly don't contain much logic - so i thought it could be ok to just use public fields. – Moneybag