To delete selected values in MVC asp.net

Posted by Shasseb under ASP.NET on 4/10/2013 | Points: 10 | Views : 1193 | Status : [Member] | Replies : 1
Hello!

I have a problem. Actually i want to delete more than one item by just single click in my project using MVC4 without using any gridview kindly please provide me some code example to solve my problem..

here is my code

View:
using (Html.BeginForm())
{
<a href=@Href("/Location/Add") class="bt_red"><span class="bt_green_lft"></span><strong>Add New Place</strong><span class="bt_green_r"></span></a>
<a href="#" class="bt_red"><span class="bt_blue_lft"></span><strong>View all Places from category</strong><span class="bt_blue_r"></span></a>
<a class="bt_red" href="@Url.Action("DeleteAll")"><span class="bt_red_lft"></span><strong>Delete Places</strong><span class="bt_red_r"></span></a>


<div class="pagination">
<span class="disabled"><< prev</span><span class="current">1</span><a href="">2</a><a href="">3</a><a href="">4</a><a href="">5</a>.<a href="">10</a><a href="">11</a><a href="">12</a>...<a href="">100</a><a href="">101</a><a href="">next >></a>
</div>
<br /><br />

<br /><br />
}

Controller:
[HttpPost]
public ActionResult DeleteAll(int[] MyCheckboxes)
{
DatabaseEntities4 db = new DatabaseEntities4();
//string[] MyCheckboxes = collection.GetValues("MyCheckboxes");


foreach (var item in MyCheckboxes)
{
var q = from s in db.Places
where s.Place_Id == Convert.ToInt32(item)
select s;
foreach (var t in q)
{
db.Places.DeleteObject(t);
}
db.SaveChanges();
}

return RedirectToAction("location", "Login");
}





Responses

Posted by: Johnkdavis on: 4/23/2013 [Member] Starter | Points: 25

Up
0
Down
Use Json post method to delete all the selected item.

Shasseb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response