I have a fairly complex ViewModel containing decimal
properties, which are exposed to the user in the form of text boxes. I want a textbox with no value to be interpreted as zero. (The properties in the underlying domain object are non-nullable, and the default value is 0.)
When the DefaultModelBinder
binds the view data to the ViewModel, decimal properties with blank strings for inputs are initialized to zero (as is standard in .NET), but the DefaultModelBinder
is adding errors to the ModelState for the blank text boxes. As a result the ModelState is invalid and the user sees a whole bunch of "A value is required." errors for the textboxes they left blank.
How can I stop these errors from being added to the ModelState?