Reputation: 49
I want to delete all the records of the table. I am able to delete based on id, but I don't want based on id. My sql server table name is [EnergyMonitoringDB].[dbo].[Energies]
How to delete it.
The code:
public string Delete_AllEnergyData() {
using (EnergyMonitoringDBEntities Obj = new EnergyMonitoringDBEntities())
{
Obj.Energies.RemoveRange(Obj.Energies);
Obj.SaveChanges();
return "Energy Data Deleted Successfully";
}
}
AngularJS code:
$scope.DeleteAll = function () {
$http({
method: "post",
url: "http://localhost:3523/Admin/Home/Delete_AllEnergyData",
datatype: "json",
data: JSON.stringify(Emp)
}).then(function (response) {
alert(response.data);
$scope.GetAllData();
})
};
html code:
<input type="button" class="btn btn-danger" value="Delete All" ng-click="DeleteAll()" />
Upvotes: 0
Views: 363
Reputation: 5370
Delete_AllEnergyData
does not have any parameter. So remove sending parameter data: JSON.stringify(Emp)
to controller as following:
$scope.DeleteAll = function () {
$http({
method: "post",
url: "http://localhost:3523/Admin/Home/Delete_AllEnergyData",
}).then(function (response) {
alert(response.data);
$scope.GetAllData();
})
};
Upvotes: 3