How to get the checked checkbox from a ASP.NET MVC2 form

Posted by JF on Stack Overflow See other posts from Stack Overflow or by JF
Published on 2010-06-18T13:46:04Z Indexed on 2010/06/18 13:53 UTC
Read the original article Hit count: 1041

Filed under:

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" id="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

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2