[英]how to delete all records from the table using entityframework in mvc
我想删除表的所有记录。 我可以根据 id 删除,但我不想根据 id 删除。 我的sql server表名是[EnergyMonitoringDB].[dbo].[Energies]
怎么删除。
编码:
public string Delete_AllEnergyData() {
using (EnergyMonitoringDBEntities Obj = new EnergyMonitoringDBEntities())
{
Obj.Energies.RemoveRange(Obj.Energies);
Obj.SaveChanges();
return "Energy Data Deleted Successfully";
}
}
AngularJS 代码:
$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代码:
<input type="button" class="btn btn-danger" value="Delete All" ng-click="DeleteAll()" />
Delete_AllEnergyData
没有任何参数。 因此删除发送参数data: JSON.stringify(Emp)
到控制器如下:
$scope.DeleteAll = function () {
$http({
method: "post",
url: "http://localhost:3523/Admin/Home/Delete_AllEnergyData",
}).then(function (response) {
alert(response.data);
$scope.GetAllData();
})
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.