title: How to set a checkbox value in code
body: <p>Hi I have some code like:</p>
  
  <pre><code>foreach (var item in Model) {
          &lt;div&gt;
              @Html.DisplayFor(modelItem =&gt; item.UserRole.Role.Name)
          &lt;/div&gt;
          &lt;div&gt;
              &lt;input type="checkbox" name="ids" checked="@item.Active" /&gt;
          &lt;/div&gt;
      }
  </code></pre>
  
  <p>What I was trying to achieve was set the checkbox check if item is Active else not checked.</p>
  
  <p>I understand the syntax should be <code>checked="checked"</code> and I've set it up as <code>checked="true"</code></p>
  
  <p>I don't understand how to convert the true to checked and what to do for false.</p>
  
  <p>I was trying to use a ternary but it wouldn't play nice. Can anybody help?</p>