Error while deleting record in angularjs

Posted by Klbaiju under AngularJS on 5/30/2017 | Points: 10 | Views : 201 | Status : [Member] | Replies : 2
delete function is not working in my application
controller code
ExerciseEntities1 Db = new ExerciseEntities1();

// GET: /Employee/
public ActionResult Index()
{
return View("Index", "", GetEmployee());
}
public JsonResult GetEmployee()
{
var emp = Db.Employees.ToList();
return Json(emp, JsonRequestBehavior.AllowGet);
}

//
//
[HttpDelete]
public JsonResult DeleteEmployee(int Id)
{
Employee emp = Db.Employees.Find(Id);
Db.Employees.Remove(emp);
Db.SaveChanges();
return Json(emp, JsonRequestBehavior.AllowGet);
}

//
}

<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script>
var angular = angular.module('mvcapp', []);

angular.controller('DemoController', function ($scope, $http) {

GetAllData();
$scope.isDisabledupdate = true;
//Get All Employee
function GetAllData() {
$http.get('/Employee/GetEmployee').success(function (data) {

$scope.employees = data;

});
};
//



$scope.deleteemp = function (empModel) {
debugger
varIsConf = confirm('Want to delete ' + empModel.FirstName + '. Are you sure?');
if (varIsConf) {
$http.delete('/Employee/DeleteEmployee/' + empModel.Id).success(function () {
$scope.errors = [];
GetAllData();
alert(empModel.Name + " Deleted Successfully!!!");
}).error(function () {
alert(data.errors);
});
}
};
});

</script>

when i try to delete the record of id
following error showing
http://localhost:8112/Employee/DeleteEmployee/10 not found
code in controller is not firing

How to solve this

Regards

Baiju




Responses

Posted by: Jayakumars on: 6/2/2017 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi

can you share your code zip format then only we can check easily.

Mark as Answer if its helpful to you

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

Posted by: Cannyq on: 7/31/2017 [Member] Starter | Points: 25

Up
0
Down
Yes, he is right, without complete file can't solve this.
for angularjs training for books visit www.cannyq.com

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

Login to post response