tags:

views:

25

answers:

1

Is there any sample code of how to read the id of the selected checkbox in a view from a controller.

<% foreach (var item in Model.projects) { %>
     <tr><td><input type="checkbox" name="selectedObjects" value=" <%=item.ID %>"> 
    <%=item.Name %>

    <% } %>

What must be the code on the controller to get the ID of the selected checkboxes?

A: 

Add a parameter named "selectedObjects" to your action method, and it will be populated by the selected values.

public ActionResult myPostAction(int[] selectedObjects)
{
     foreach (var value in selectedObjects)
     {

     }
}
womp
I need to do the fllowing:I the controller I need to 1. Get the Id associated with each checkbox2. Verify if the each of the checkbox is selected or not