I have a hard time in asp.net MVC2 trying to get the checked values of different checkbox.
Here is my view
<div id="RoleSelection">
<ul>
<% foreach (var roles in Model.Roles)
{
%>
<li>
<input type="checkbox" name="roles" value="<%: roles %>" /> <%: roles %>
</li>
<%
}
%>
</ul>
</div>
My model:
[LocalizedDisplayName("Role", NameResourceType = typeof(UserResources))]
public string Role { get; set; }
public IEnumerable<string> Roles { get; set; }
So basically here I’m trying to figure out how to get all the checked checkbox from my form!
Thank you
Use the
Nameattribute instead of theidattribute. Theidmust be unique amongst all element.The
nameattribute in your case will allow you to regroup the multiple checkbox into a single group.