title: Custom model binder not firing for a single property in ASP.NET Core 2
body: <p>I already have tried <a href="https://stackoverflow.com/questions/54661799/apply-custom-model-binder-to-object-property-in-asp-net-core">this</a>, but I don't think it's my case. <a href="https://stackoverflow.com/questions/44870933/asp-net-core-custom-model-binder-just-for-one-property">This</a> doesn't work neither.</p>
  
  <p>I'm using ASP.NET Core 2 Web API. I just created a dummy model binder (what it does doesn't matter for now):</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class SanitizeModelBinder : IModelBinder
  {
      public Task BindModelAsync(ModelBindingContext bindingContext)
      {
          if (bindingContext == null)
          {
              throw new ArgumentNullException(nameof(bindingContext));
          }
  
          var modelName = bindingContext.ModelName;
  
          return Task.CompletedTask;
      }
  }
  </code></pre>
  
  <p>Now, I have a model. This one:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class UserRegistrationInfo
  {
      public string Email { get; set; }
  
      [ModelBinder(BinderType = typeof(SanitizeModelBinder))]
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>And an action method:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[AllowAnonymous]
  [HttpPost("register")]
  public async Task&lt;IActionResult&gt; RegisterAsync([FromBody] UserRegistrationInfo registrationInfo)
  {
      var validationResult = validateEmailPassword(registrationInfo.Email, registrationInfo.Password);
      if (validationResult != null) 
      {
          return validationResult;
      }
  
      var user = await _authenticationService.RegisterAsync(registrationInfo.Email, registrationInfo.Password);
  
      if (user == null)
      {
          return StatusCode(StatusCodes.Status500InternalServerError, "Couldn't save the user.");
      }
      else
      {
          return Ok(user);
      }
  }
  </code></pre>
  
  <p>If I make a post request from the client, my custom model binder isn't fired and the execution continues in the action method.</p>
  
  <p><strong>Things I have tried:</strong></p>
  
  <p>Applying the <code>ModelBinder</code> attribute to the whole model object:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[ModelBinder(BinderType = typeof(SanitizeModelBinder))]
  public class UserRegistrationInfo
  {
      public string Email { get; set; }
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>This works, but for the whole object, and I don't want that. I want the default model binder to do its job and then, apply my custom model binder to certain properties only.</p>
  
  <p>I read <a href="https://github.com/aspnet/Mvc/issues/4553" rel="noreferrer">here</a> that it's the <code>FromBody</code> 's fault, so I removed it from the action method. It doesn't work neither.</p>
  
  <p>I tried to change the attribute <code>ModelBinder</code> for <code>BindProperty</code> here:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class UserRegistrationInfo
  {
      public string Email { get; set; }
  
      [BindProperty(BinderType = typeof(SanitizeModelBinder))]
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>But it doesn't work.</p>
  
  <p>It's quite disapointing that something that should be simple is turning to be quite cumbersome, and the information scattered on several blogs and github issues isn't helping at all. So please, if you can help me, it would be really appreciated.</p>