Model Binding - Nullable decimal and double default to 0 instead of null?

vgjhav

New Member
When my form posts to my controller action, and the form is bound to my model, blank form values for nullable doubles and decimals default to 0, but blank form values for nullable ints default to null. Is this right?My model has nullable types for several fields that can be blank. It has nullable ints, doubles, and decimals. I then have a regular form that has textboxes for each of these properties, and they all default to blank (empty string). When this form is posted back to my controller action with all empty form values, and it's bound to my model, the empty doubles and decimals show up as 0, and the empty ints are null.It seems to me all nullable types should default to null when an empty form value is passed in, but even if that's not the case, it seems very inconsistent that doubles and decimals are treated different than ints.
 
Back
Top