Denmark Puso

Denmark Puso

  • NA
  • 232
  • 50.3k

Delete not working

Sep 18 2019 2:58 AM
im using c# mvc5 my delete not working see my code.
 
  1. public ActionResult Delete(int id)  
  2.         {  
  3.             var shipmentItem = _shipmentItemService.Get(id);  
  4.             _shipmentItemService.Remove(shipmentItem);  
  5.             return RedirectToAction("shipmentlistmodel");  
  6.         }     
 
this is my view script
 
  1. $(function () {  
  2.        $('#ShipmentItemList').DataTable({  
  3.            "ajax""@Url.Action("getshipmentitemlist", "shipment")?shipmentId=" + @ViewBag.ShipmentId,  
  4.            "columns": [  
  5.                { "data""ShipmentName" },  
  6.                { "data""PackageNumber" },  
  7.                { "data""TrackingNumber" },  
  8.                { "data""ClientName" },  
  9.                { "data""Status" },  
  10.                {  
  11.                    "render"function (data, type, full, meta) {  
  12.                        return "<a href='#' class='btn btn-danger' onclick=DeleteData('" + full.id + "'); >Delete</a>";   
  13.                    }  
  14.                }  
  15.            ]  
  16.        });  
  17.    });  
  18.   
  19.    function DeleteData(id) {    
  20.        if (confirm("Are you sure you want to delete..?")) {    
  21.            Delete(id);    
  22.        }    
  23.        else {    
  24.            return false;    
  25.        }    
  26.    }    
  27.          
  28.    function Delete(id) {    
  29.        var del = "@Url.Action("delete", "shipment")?id=" + id;  
  30.        $.post(del, { id: id }, function (data) {    
  31.            if (data == "Deleted") {    
  32.                alert("Delete Customer !");    
  33.                Table = $('#ShipmentItemList').DataTable();    
  34.                Table.draw();    
  35.            }    
  36.            else {    
  37.                alert("Something Went Wrong!");    
  38.            }    
  39.        });    
  40.    }    
 
 

Answers (3)