title: Razor C# - Setting up checkbox values
body: <p>I have my form with my checkbox inputs, and user can edit that. I can save these values in database good, but I don't know how to refill the form, so user can edit it.</p>
  
  <p>This is my ViewBag var:</p>
  
  <pre><code> ViewBag.NewFriends = preferences.NewFriends;// this value is a boolean, false
  </code></pre>
  
  <p>I try to pre-set values like this:</p>
  
  <pre><code>@using (Html.BeginForm("SavePreferences", "Conta"))
  {
      @Html.HiddenFor(model =&gt; model.ID)
      @Html.CheckBox("newFriends", new { @checked = @ViewBag.NewFriends })
      @Html.Label("newFriends", "Solicitações de Amigo de Alma")
      &lt;p&gt;&lt;input type="submit" value="Send" /&gt;&lt;/p&gt;
  }
  </code></pre>
  
  <p>As HTML checkbox has the value checked="checked", and not true or false, it doesn't work.
  @Html.CheckBox has the first parameter as input name, and second a boolean checked(true or false).</p>
  
  <p>My question is how can I easily set up this value? I tried:</p>
  
  <pre><code>@Html.CheckBox("newFriends", ViewBag.NewFriends) // where ViewBag.NewFriends = false
  </code></pre>
  
  <p>But it doesn't work at all...</p>
  
  <p>Any idea?</p>