Correct `ModelMetadata.IsRequired` to honour overrides

- subclasses would not calculate a value because `ModelMetadata` constructor
  set this property
- meant presence of a `[Required]` attribute in the model was ignored
This commit is contained in:
dougbu 2014-06-13 12:36:41 -07:00
parent 80a27c6f3b
commit 48085eea08
1 changed files with 12 additions and 3 deletions

View File

@ -18,7 +18,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private readonly string _propertyName;
private EfficientTypePropertyKey<Type, string> _cacheKey;
private bool _convertEmptyStringToNull = true;
// Backing fields for virtual properties with default values.
private bool _convertEmptyStringToNull;
private bool _isRequired;
private object _model;
private Func<object> _modelAccessor;
private int _order = DefaultOrder;
@ -40,7 +43,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
_modelAccessor = modelAccessor;
_modelType = modelType;
_propertyName = propertyName;
IsRequired = !modelType.AllowsNullValue();
_convertEmptyStringToNull = true;
_isRequired = !modelType.AllowsNullValue();
}
public Type ContainerType
@ -76,7 +81,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public virtual bool IsReadOnly { get; set; }
public virtual bool IsRequired { get; set; }
public virtual bool IsRequired
{
get { return _isRequired; }
set { _isRequired = value; }
}
public virtual int Order
{