title: Why MVC binding models require properties rather than fields
body: <p>I'm developing a web application with ASP.NET Core with MVC. The controllers' actions that handle POST requests from a HTML <code>form</code> usually accept a parameter used as a binding model like:</p>
  
  <pre><code>[HttpPost]
  public IActionResult Edit(ModelBindingClass userInput)
  </code></pre>
  
  <p>I discovered that the class for a binding model, in the example above <code>ModelBindingClass</code>, must respect two conditions:</p>
  
  <ol>
  <li>Have a parameterless constructor</li>
  <li>Have <strong>publicly settable properties</strong> to store user inputs</li>
  </ol>
  
  <p>I suppose the first condition is to ensure the MVC middleware can easily instantiate an object.</p>
  
  <p>But <strong>why it can't make use of public fields</strong> rather than properties?</p>
  
  <pre><code>public class ModelBindingClass
  {
      public int Age { get; set; } // binder will set it correctly
  
      public int Height; // binder will not
  }
  </code></pre>
  
  <p>Any answer pointing to the related source code is welcomed. Thank! :-) </p>