title: String Trim Model Binder in ASP .NET Core 2
body: <p>I'm working on a .NET Core 2 API project and have been trying to implement a universal string trim model binder that would trim all string values of provided request parameters and field values. So far I have had mixed results and am struggling to find working example that would point me in the right direction. I've been trying to implement the same model binder as <a href="https://vikutech.blogspot.com/2018/02/trim-text-in-mvc-core-through-model-binder.html" rel="noreferrer">posted by Vikash Kumar</a>.</p>
  
  <p>This model binder works fine for all string values that are passed into controller actions via direct parameters, such as <code>public IActionResult Profile(string username)</code>, but for string fields in complex objects the <code>BindModelAsync</code> method of the <code>TrimmingModelBinder</code> class never gets called. An example of an HttpPost action in my controller would be <code>public IActionResult Profile([FormBody] ProfileLookupModel model)</code>. The model binder does not seem to check the fields of the complex model. It also doesn't work for fields that are Lists of strings.</p>
  
  <p>I recall prior to .NET Core, specifying a string trim model binder would recursively check each field of complex models, even models within complex models. This doesn't seem to be the case in .NET Core, but I might be wrong. My project is targeting the <code>netcoreapp2.0</code> framework.</p>
  
  <p>I'm curious if anyone has had the same issue as me and possibly found a solution for it.</p>
  
  <p>Note: I haven't posted any sample code as it is the same as the code from the referenced article.</p>