Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
//
        // POST: /ManageContact/Delete/5
        [HttpPost]
        public ActionResult Delete(ContactsViewModel model)
        {
            var contact = _contactService.GetContactById(model.Id);

            if (contact == null)
                return View();

            var idArray = new[] { model.Id };
            _contactService.RemoveContact(idArray);

            return RedirectToAction("Index");
        }

this the contact controller

HTML
@using (Html.BeginForm())
        {
            <div>
                <h4 class="center">Available Contact(s)</h4><br /><div>
                    @Html.AntiForgeryToken()

                </div>
            </div><div class="span12"></div>
            <div class=" btn-group">
                <input class="btn btn-info " type="submit" value=" Send Message"><input class="btn btn-info " type="submit" value=" Add to Group"><input class="btn btn-info  " type="submit" value=" Delete Contacts">
            </div>
        }
        <div class="span11 blog-item ">
            <div class="row-fluid">
                <div class="span12">
                    <table class="table table-striped table-hover table-bordered">
                        <thead>
                            <tr>
                                <th></th>
                                <th><h4 class="center">Contact Name(s)</h4></th>
                                <th><h4 class="center">Mobile Number(s)</h4></th>
                                <th><h4 class="center">Actions</h4></th>
                            </tr>
                        </thead>
                        @foreach (var item in Model)
                        {
                            <tbody>
                                <tr>
                                    <td><input type="checkbox" value="@item.Id" name="deleteInputs"></td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Name, new { @class = "center" })
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.MobileNumber, new { @class = "center" })
                                    </td>
                                    <td>
                                        <a data-toggle="modal" href="#loginForm">Add To Group</a>
                                        @*@Html.ActionLink("Add to Group", "AddtoGroup", new { }, new { @class = "center", })*@ |
                                        @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "center" }) |
                                        @Html.ActionLink("Delete", "Delete", new { id = item.Id })
                                    </td>
                                </tr>
                            </tbody>
                        }

                    </table>

And this is the view that display every contacts in a table...

So please how do i go about selecting multiple contact using the checkbox and delete with the button in my controller and am using Services with Repository
Posted

1 solution

 
Share this answer
 
Comments
Member 10765778 23-May-14 8:07am    
yea i get that thanks but there is still a little problem...
how do i assign (var idArray = new[] { model.Id };) to ( var chckedValues = form.GetValues("assignChkBx");)
Ayan Chalki 26-May-14 7:26am    
In my example "webGrid" is used not "table tr td". And in that webgrid, "assignChkBx" column is added with value="@item.Id". so replace var idArray = new[] { model.Id }; with var idArray = form.GetValues("assignChkBx");). Do you get it what I said?
Member 10765778 27-May-14 4:31am    
oka it help Tanks very mush

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900