<script type="text/javascript"> function DeleteVehicle() { alert("working"); if (confirm("Do you want to delete vehicle: " + id)) { //fetch id wherever you are fetching var id = $(this).attr(id); $.ajax({ type: "POST", contentType:"application/json;charset=utf-8", url: '@Url.Action("DeleteVehicle", "Vehicle")', data: { "id": id }, dataType:"json", success: function (data) { alert("Success, sent data to controller"); }, error: function (data) { alert("Error: " + data.responseText); } }); } } $(function () {//when the document is ready $("#Delete").click(DeleteVehicle); }); </script>
[HttpPost] public JsonResult DeleteVehicle(string id) { string userName = "someUserName"; bool result = false; try { result = ovehc.RemoveVehicle(id, userName); } catch (Exception ex) { } return Json(new { result }, JsonRequestBehavior.AllowGet); }
data: "{'id':'" + id + "'}",
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)