How can I get the checkbox values which are true from a dynamically generated list of checkboxes? My example contains three boxes, but I am using a Razor view to create many more. I tried basing my code off of this SO post with no luck.
In my View:
<CheckBoxList ID="cheesebox">
<ListItem>1</ListItem>
<ListItem>2</ListItem>
<ListItem>3</ListItem>
</CheckBoxList>
Controller:
public ActionResult GCLanding(IFormCollection form)
{
var selectedValues = form["cheesebox"].ToString();
return View("StringView", " & "+selectedValues);
}
My goal is the get the checkbox value for whichever boxes are checked. For example a List containing 1,2,3 if all three boxes are checked.