ASP.NET MVC: Render checkbox list from MultiSelectList
Posted
by aximili
on Stack Overflow
See other posts from Stack Overflow
or by aximili
Published on 2010-03-04T06:18:23Z
Indexed on
2010/04/08
3:03 UTC
Read the original article
Hit count: 1192
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?)
© Stack Overflow or respective owner