1

Okay, right now I have a form that contains this select list:

<%=Html.LabelFor(x => x.Id)%>
    <%= Html.ListBoxFor(x => x.Ids, new SelectList(Model.Items, "ID", "Name", Model.Ids)) %><br />

And here is my controller, where I add the data to the database:

foreach (var id in model.Ids)
            {
                tool.ToolItems.Add(new ToolItem { ID = id });
            }

Now, I decided to use checkboxes instead of a selectlist, here is that code:

<% foreach (var item in Model.Tools)
       { %>
        <input type="checkbox" name="tool" value="<%= item.ID %>" />
            <%= tool.Name %>
        </>
    <% } %><br />

I have no idea what to do in my controller tho to get all the selected checkboxes.

Sorry if some of the variables dont make sense, I tried to change it as consistently as possible since I cant post the actual stuff.

RJP
  • 4,016
  • 5
  • 29
  • 42

1 Answers1

0

You might find the following question helpful: Passing checkbox selection through to an action

To answer your question, your controller action probably needs to look like this:

public ActionResult MyAction(string[] tool) {
    // "tool" will contain the values of all checked boxes!
}
Community
  • 1
  • 1
Scott Rippey
  • 15,614
  • 5
  • 70
  • 85