ASP.NET - Multiple records delete in MVC - Asked By Partha Chakraborty on 11-May-13 06:18 AM

Hi,
I am trying  to delete multiple records in a MVC3 razor application. I am using WebGrid and and there is a checkbox in each row of the grid. I want to delete multiple records after selecting more than one checkbox and then clicking a submit button, which is a common practice. But my question is how can I pass all the check box values from view to controller after giving a confirmation message?

Here is my code:

<script type="text/javascript">

    //Select/Deselect all checkboxs in the grid
    $(document).ready(function () {
      $("#toggleAllCheckBox").click(function () {
        if ($(this).attr("checked")) {
          $(".check-box").attr("checked", true);

        } else {
          $(".check-box").attr("checked", false);
        }
      });
    });
</script>

<div style="margin-left:5px;" ><input id="toggleAllCheckBox" type="checkbox"/>@Html.ActionLink("Delte", "Edit")</div>
@grid.GetHtml(
    fillEmptyRows: false,
    alternatingRowStyle: "alternate-row",
    headerStyle: "grid-header",
    footerStyle: "grid-footer",
    mode: WebGridPagerModes.All,
    firstText: "<< First",
    previousText: "< Prev",
    nextText: "Next >",
    lastText: "Last >>",
    columns: new [] {
      grid.Column(header: "", format: @<text><input class="check-box" type="checkbox" id="assignChkBx" value="@item.CustomerID" /></text>),
      grid.Column("CustomerID", "CustomerID", canSort: true, style: "CustomerID"),
      grid.Column("CompanyName", "Company Name", canSort: true, style: "CompanyName"),
      grid.Column("ContactName", "Contact Name", canSort: true, style: "ContactName"),
      grid.Column("Address", "Address", canSort: false, style: "Address"),
      grid.Column("City", "City", canSort: true, style: "City"),
       
      grid.Column("",
            header: "Actions",
            format: @<text>
                  @Html.ActionLink("Edit",   "Edit",   new { id=item.CustomerID} )
                  @Html.ActionLink("Delete", "Delete", new { id=item.CustomerID} )
                </text>
      )
      
})

Any help will be thankfully accepted.
Partha