[英]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.