ASP.NET MVC: Render checkbox list from MultiSelectList
- by aximili
How do you associate a MultiSelectList with a list of checkboxes?
eg. I pass something like this to the model
model.Groups = new MultiSelectList(k.Groups, "Id", "Name", selectedGroups)
How should I render it? This doesn't work
<% foreach (var item in Model.Groups.Items) { %>
<input type="checkbox" name="groups" value="<%=item.Value%>" id="group<%=item.Value%>" checked="<%=item.Selected?"yes":"no"%>" />
<label for="group<%=item.Value%>"><%=item.Text%></label>
<% } %>
Error CS1061: 'object' does not contain a definition for 'Value'...
Is there a HTML Helper method that I can use?
(Then, unless it is straightforward, how should I then get the selected values back on the Controller when the form is submitted?)