开发者

mvc sample code to read the id of the selected checkbox

开发者 https://www.devze.com 2022-12-16 06:01 出处:网络
Is there any sample code of how to read th开发者_运维问答e id of the selected checkbox in a view from a controller.

Is there any sample code of how to read th开发者_运维问答e 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?


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)
     {

     }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消