diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs index cb68815d6b..82fea79acf 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs @@ -76,20 +76,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return Task.FromResult(Success(key, model, validationNode)); } - /// - /// Creates a new using the provided . - /// - /// The key of the current model binding operation. - /// The other to copy from. - public ModelBindingResult([NotNull] string key, ModelBindingResult other) - { - Key = key; - - Model = other.Model; - IsModelSet = other.IsModelSet; - ValidationNode = other.ValidationNode; - } - private ModelBindingResult(string key, object model, bool isModelSet, ModelValidationNode validationNode) { Key = key; @@ -171,7 +157,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } else if (IsModelSet) { - return $"Success {Key} -> {Model}"; + return $"Success {Key} -> '{Model}'"; } else { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs index 1156585055..40ed1ee1bd 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs @@ -32,51 +32,16 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// public IReadOnlyList ModelBinders { get; } - public virtual async Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public virtual Task BindModelAsync([NotNull] ModelBindingContext bindingContext) { var newBindingContext = CreateNewBindingContext(bindingContext); if (newBindingContext == null) { // Unable to find a value provider for this binding source. Binding will fail. - return ModelBindingResult.NoResult; + return ModelBindingResult.NoResultAsync; } - var modelBindingResult = await RunModelBinders(newBindingContext); - if (modelBindingResult == ModelBindingResult.NoResult) - { - // Unable to bind or something went wrong. - return ModelBindingResult.NoResult; - } - - var bindingKey = bindingContext.ModelName; - if (modelBindingResult.IsModelSet) - { - // Update the model state key if we are bound using an empty prefix and it is a complex type. - // This is needed as validation uses the model state key to log errors. The client validation expects - // the errors with property names rather than the full name. - if (newBindingContext.ModelMetadata.IsComplexType && string.IsNullOrEmpty(modelBindingResult.Key)) - { - // For non-complex types, if we fell back to the empty prefix, we should still be using the name - // of the parameter/property. Complex types have their own property names which acts as model - // state keys and do not need special treatment. - // For example : - // - // public class Model - // { - // public int SimpleType { get; set; } - // } - // public void Action(int id, Model model) - // { - // } - // - // In this case, for the model parameter the key would be SimpleType instead of model.SimpleType. - // (i.e here the prefix for the model key is empty). - // For the id parameter the key would be id. - bindingKey = string.Empty; - } - } - - return new ModelBindingResult(bindingKey, modelBindingResult); + return RunModelBinders(newBindingContext); } private async Task RunModelBinders(ModelBindingContext bindingContext)