ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Remove multiple Rows from Database using AngularJS in ASP.Net MVC<p>Hi <a class="username" rel="mahesh213"> mahesh213</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(); } public JsonResult GetOrders() { return Json(OrdersList(), JsonRequestBehavior.AllowGet); } public JsonResult GetItemsByOrderId(int? id) { List&lt;Item&gt; items = ItemsList().Where(x =&gt; x.OrderId == id).ToList(); return Json(items, JsonRequestBehavior.AllowGet); } public JsonResult Save(string[] items) { for (int i = 0; i &lt; items.Length; i++) { JavaScriptSerializer se = new JavaScriptSerializer(); DeletedItem deleted = se.Deserialize&lt;DeletedItem&gt;(items[i].ToString()); // Write code to remove from database. foreach (Item item in ItemsList().ToList()) { if (item.Id == deleted.Id &amp;&amp; item.OrderId == deleted.OrderId) { ItemsList().Remove(item); } } } // Get updated record from database after delete. return Json(items.ToList(), JsonRequestBehavior.AllowGet); } private static List&lt;Order&gt; OrdersList() { List&lt;Order&gt; orders = new List&lt;Order&gt;(); orders.Add(new Order { OrderId = 1, OrderName = &#34;Order 1&#34; }); orders.Add(new Order { OrderId = 2, OrderName = &#34;Order 2&#34; }); return orders; } private static List&lt;Item&gt; ItemsList() { List&lt;Item&gt; items = new List&lt;Item&gt;(); items.Add(new Item { OrderId = 1, Id = 1, Name = &#34;Item 1&#34; }); items.Add(new Item { OrderId = 1, Id = 2, Name = &#34;Item 4&#34; }); items.Add(new Item { OrderId = 2, Id = 3, Name = &#34;Item 3&#34; }); items.Add(new Item { OrderId = 2, Id = 4, Name = &#34;Item 2&#34; }); return items; } public class Order { public int OrderId { get; set; } public string OrderName { get; set; } } public class Item { public int OrderId { get; set; } public int Id { get; set; } public string Name { get; set; } } public class DeletedItem { public int OrderId { get; set; } public int Id { get; set; } } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head&gt; &lt;title&gt;Index&lt;/title&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; var app = angular.module(&#39;MyApp&#39;, []); app.controller(&#39;MyController&#39;, function ($scope, $http) { PopulateOrders(); $scope.GetItems = function (orderId) { $http({ method: &#39;Get&#39;, url: &#39;/Home/GetItemsByOrderId/&#39;, params: { id: orderId} }) .success(function (data) { if (data.length &gt; 0) { $scope.Items = data; } else { $scope.Items = []; } }); } $scope.DeletedItems = []; $scope.DeleteItem = function (item) { var obj = {}; obj.OrderId = item.OrderId; obj.Id = item.Id; $scope.DeletedItems.push(obj); var index = $scope.Items.indexOf(item); $scope.Items.splice(index, 1); } $scope.Save = function () { $http({ method: &#39;Get&#39;, url: &#39;/Home/Save/&#39;, params: { items: $scope.DeletedItems} }) .success(function (data) { }); } function PopulateOrders() { $scope.Orders = []; $http({ method: &#39;Get&#39;, url: &#39;/Home/GetOrders/&#39; }) .success(function (data) { if (data.length &gt; 0) { $scope.Orders = data; } else { $scope.Orders = []; } }); } }); &lt;/script&gt; &lt;/head&gt; &lt;body ng-app=&#34;MyApp&#34; ng-controller=&#34;MyController&#34;&gt; &lt;table class=&#34;table table-responsive&#34;&gt; &lt;tr&gt; &lt;th&gt;Order Id&lt;/th&gt; &lt;th&gt;Order Name&lt;/th&gt; &lt;th&gt;&amp;nbsp;&lt;/th&gt; &lt;/tr&gt; &lt;tr ng-repeat=&#34;order in Orders&#34;&gt; &lt;td&gt;{{order.OrderId}}&lt;/td&gt; &lt;td&gt;{{order.OrderName}}&lt;/td&gt; &lt;td&gt;&lt;input type=&#34;button&#34; value=&#34;Get Items&#34; ng-click=&#34;GetItems(order.OrderId)&#34; class=&#34;btn btn-sm btn-primary&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;table class=&#34;table table-responsive&#34; ng-show=&#34;Items&#34;&gt; &lt;tr&gt; &lt;th&gt;Item Id&lt;/th&gt; &lt;th&gt;Item Name&lt;/th&gt; &lt;th&gt;Delete&lt;/th&gt; &lt;/tr&gt; &lt;tr ng-repeat=&#34;item in Items&#34;&gt; &lt;td&gt;{{item.Id}}&lt;/td&gt; &lt;td&gt;{{item.Name}}&lt;/td&gt; &lt;td&gt;&lt;input type=&#34;button&#34; value=&#34;Delete&#34; ng-click=&#34;DeleteItem(item)&#34; class=&#34;btn btn-sm btn-danger&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;center&gt; &lt;input type=&#34;button&#34; value=&#34;Save&#34; ng-click=&#34;Save()&#34; class=&#34;btn btn-md btn-success&#34; /&gt; &lt;input type=&#34;button&#34; value=&#34;Cancel&#34; class=&#34;btn btn-md btn-default&#34; /&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/dxB1K25.gif" alt="" width="335" height="362" /></p> <p><span style="text-decoration: underline;">Deleted Items in controller</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/BRJTJ9b.jpg" alt="" width="472" height="77" /></span></p>https://www.aspforums.net:443/Threads/109424/Remove-multiple-Rows-from-Database-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/109424/Remove-multiple-Rows-from-Database-using-AngularJS-in-ASPNet-MVC/Thu, 08 Aug 2019 06:56:20 GMT