title: asp.net core razor page checkboxes model binding (always false)
body: <p>i have a razor page in asp.net core with the following input tag:</p>
  
  <pre><code>&lt;input asp-for="chkPref" /&gt;
  </code></pre>
  
  <p>in the code-behind i have:</p>
  
  <pre><code>public bool chkPref { get; set; }
  </code></pre>
  
  <p>so when i run the app, i can confirm in <code>Request.Form</code> that I'm getting...</p>
  
  <p>checkbox checked = <code>{true,false}</code></p>
  
  <p>checkbox unchecked = <code>{false}</code></p>
  
  <p>which is expected, according to <a href="https://www.learnrazorpages.com/razor-pages/forms/checkboxes" rel="nofollow noreferrer">https://www.learnrazorpages.com/razor-pages/forms/checkboxes</a> (which seems to be the site everyone points to for answers to this issue)</p>
  
  <p>however, that page states that the model binding will figure out that <code>{true,false}</code> is actually <code>true</code> but i'm getting <code>false</code> no matter what.</p>
  
  <p>the website above alludes to the fact that this "just happens"...</p>
  
  <blockquote>
    <p>If the checkbox is checked, the posted value will be true,false. The
    model binder will correctly extract true from the value. Otherwise it
    will be false.</p>
  </blockquote>
  
  <p>but that doesn't seem to be working, or at least isn't that obvious how it works.</p>
  
  <p>i'm not exactly sure how you can assign two values (ie - <code>true</code>, <code>false</code>) to a single <code>bool</code> in the first place.</p>
  
  <p>i even tried turning it into a <code>List&lt;bool&gt;</code> but that didn't work either. that throws a whole different set of errors.</p>