title: Custom Model Binding in Asp .Net Core
body: <p>i'm trying to bind a model with a <em>IFormFile</em> or <em>IFormFileCollection</em> property to my custom class <em>CommonFile</em>. i have not found so much documentation on internet about it using asp .net core, i tried to follow this link <a href="http://intellitect.com/custom-model-binding-in-asp-net-core-1-0/" rel="noreferrer">Custom Model Binding in ASP.Net Core 1.0</a>
  but it is binding a SimpleType property and i need to bind a complex type. Anyway i tried to make my version of this binding and i've got the following code:</p>
  
  <p><strong>FormFileModelBinderProvider.cs</strong></p>
  
  <pre><code>public class FormFileModelBinderProvider : IModelBinderProvider
  {
      public IModelBinder GetBinder(ModelBinderProviderContext context)
      {
          if (context == null) throw new ArgumentNullException(nameof(context));
  
          if (!context.Metadata.IsComplexType) return null;
  
          var isIEnumerableFormFiles = context.Metadata.ModelType.GetInterfaces().Contains(typeof(IEnumerable&lt;CommonFile&gt;));
  
          var isFormFile = context.Metadata.ModelType.IsAssignableFrom(typeof(CommonFile));
  
          if (!isFormFile &amp;&amp; !isIEnumerableFormFiles) return null;
  
          var propertyBinders = context.Metadata.Properties.ToDictionary(property =&gt; property,
              context.CreateBinder);
          return new FormFileModelBinder(propertyBinders);
      }
  }
  </code></pre>
  
  <p><strong>FromFileModelBinder.cs</strong></p>
  
  <p>the following code is incomplete because i'm not getting any result with <code>bindingContext.ValueProvider.GetValue(bindingContext.ModelName);</code> while i'm debugging everything is going well until bindingContext.ModelName has no a value and i can't bind my model From httpContext to Strongly typed Models.</p>
  
  <pre><code>public class FormFileModelBinder : IModelBinder
  {
      private readonly ComplexTypeModelBinder _baseBinder;
  
      public FormFileModelBinder(IDictionary&lt;ModelMetadata, IModelBinder&gt; propertyBinders)
      {
          _baseBinder = new ComplexTypeModelBinder(propertyBinders);
      }
  
      public Task BindModelAsync(ModelBindingContext bindingContext)
      {
  
          if (bindingContext == null) throw new ArgumentNullException(nameof(bindingContext));
  
          var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
          return Task.CompletedTask;
  
     }
  }
  </code></pre>
  
  <p>Any suggestions?</p>