diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/MutableObjectModelBinder.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/MutableObjectModelBinder.cs index d329c85376..184a1e9805 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/MutableObjectModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/MutableObjectModelBinder.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public virtual async Task BindModelAsync(ModelBindingContext bindingContext) { ModelBindingHelper.ValidateBindingContext(bindingContext); - if (!CanBindType(bindingContext.ModelType)) + if (!CanBindType(bindingContext.ModelMetadata)) { return null; } @@ -188,20 +188,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return false; } - private static bool CanBindType(Type modelType) + private static bool CanBindType(ModelMetadata modelMetadata) { // Simple types cannot use this binder - var isComplexType = !TypeHelper.HasStringConverter(modelType); - if (!isComplexType) + if (!modelMetadata.IsComplexType) { return false; } - if (modelType == typeof(ComplexModelDto)) + if (modelMetadata.ModelType == typeof(ComplexModelDto)) { // forbidden type - will cause a stack overflow if we try binding this type return false; } + return true; } diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/ModelMetadata.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/ModelMetadata.cs index 8fa258a340..6c4f03548e 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/ModelMetadata.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/ModelMetadata.cs @@ -13,6 +13,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// public abstract class ModelMetadata { + private bool? _isComplexType; + /// /// The default value of . /// @@ -254,7 +256,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// public bool IsComplexType { - get { return !TypeHelper.HasStringConverter(ModelType); } + get + { + if (_isComplexType == null) + { + _isComplexType = !TypeHelper.HasStringConverter(ModelType); + } + + return _isComplexType.Value; + } } ///