title: How to generate checkboxes from string list in viewbag?
body: <p>I have the following code in my controller method that returns the view:</p>
  
  <pre><code>public ActionResult Create()
  {
    var allprivs = new SQLRolerecord().GetAllPrivsInApp();
    ViewBag.AllPrivsInApp = allprivs;
    return View();
  }
  </code></pre>
  
  <p>where the <code>GetAllPrivsInApp</code> method returns an <code>IEnumerable&lt;string&gt;</code>. Then in the view, I have the following Razor/html in my attempt to make a list of checkboxes from the returned string list:</p>
  
  <pre><code>&lt;table&gt;
  @{
    List&lt;string&gt; privsInApp = ViewBag.AllPrivsInApp;
    foreach (var priv in privsInApp)
    {
      @Html.CheckBox(priv,  new { value = priv, @label=priv})
    }
  }
  &lt;/table&gt;
  </code></pre>
  
  <p>This generates the correct number of checkboxes I expect, however, I don't see a label next to them. When viewing the HTML source when the application is running, I can see that the <code>name</code> and several other attributes for each of the checkboxes contains the text value I expect for each of the textboxes. How can I get the text to show up next to each of the checkboxes?</p>
  
  <p>Here is a screenshot of what shows up:</p>
  
  <p><a href="https://i.stack.imgur.com/UJZYO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UJZYO.png" alt="enter image description here"></a></p>
  
  <p>And here is the source that was generated:</p>
  
  <pre><code>&lt;table&gt;
  &lt;input id="AdminRead" label="AdminRead" name="AdminRead" type="checkbox" value="AdminRead" /&gt;&lt;input name="AdminRead" type="hidden" value="false" /&gt;&lt;input id="AdminWrite" label="AdminWrite" name="AdminWrite" type="checkbox" value="AdminWrite" /&gt;&lt;input name="AdminWrite" type="hidden" value="false" /&gt;&lt;input id="Privilege1" label="Privilege1" name="Privilege1" type="checkbox" value="Privilege1" /&gt;&lt;input name="Privilege1" type="hidden" value="false" /&gt;&lt;input id="Privilege2" label="Privilege2" name="Privilege2" type="checkbox" value="Privilege2" /&gt;&lt;input name="Privilege2" type="hidden" value="false" /&gt;&lt;input id="Privilege3" label="Privilege3" name="Privilege3" type="checkbox" value="Privilege3" /&gt;&lt;input name="Privilege3" type="hidden" value="false" /&gt;&lt;input id="Privilege4" label="Privilege4" name="Privilege4" type="checkbox" value="Privilege4" /&gt;&lt;input name="Privilege4" type="hidden" value="false" /&gt;&lt;input id="Privilege5" label="Privilege5" name="Privilege5" type="checkbox" value="Privilege5" /&gt;&lt;input name="Privilege5" type="hidden" value="false" /&gt;&lt;input id="Privilege6" label="Privilege6" name="Privilege6" type="checkbox" value="Privilege6" /&gt;&lt;input name="Privilege6" type="hidden" value="false" /&gt;&lt;input id="Privilege7" label="Privilege7" name="Privilege7" type="checkbox" value="Privilege7" /&gt;&lt;input name="Privilege7" type="hidden" value="false" /&gt;&lt;input id="Privilege8" label="Privilege8" name="Privilege8" type="checkbox" value="Privilege8" /&gt;&lt;input name="Privilege8" type="hidden" value="false" /&gt;&lt;input id="Privilege9" label="Privilege9" name="Privilege9" type="checkbox" value="Privilege9" /&gt;&lt;input name="Privilege9" type="hidden" value="false" /&gt;&lt;input id="Privilege0" label="Privilege0" name="Privilege0" type="checkbox" value="Privilege0" /&gt;&lt;input name="Privilege0" type="hidden" value="false" /&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Thank you.</p>