使用jason和angularjs更新数据库 [英] Update database using jason and angularjs

查看:91
本文介绍了使用jason和angularjs更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个angularjs控制器

 angular.module('  MyApp' //  从第一部分扩展角度模块 
.controller(' BudgetAndDetails',function($ scope,BDetail){ // 解释了Part2中的控制器
$ scope.budgetdetails = [];

BDetail.GetBDetails()。then(function(d){
$ scope.budgetdetails = d.data;
});


$ scope.removeRow = function(item){

var index = $ scope.budgetdetails.indexOf(item);
< span class =code-keyword> if (index < 0 ){
$ scope.budgetdetails.push(item)

} else {
$ scope.budgetdetails.splice(index, 1

}


};

})





我已经在我的C#中编写了这个json代码控制器



 [HttpPost] 
public JsonResult更新(BudgetandDetails预算)
{
var obj = _db.budgets.FirstOrDefault(b = > budget.budget.idBudget == b.idBudget);

_db.budgets.Remove(obj);


_db.SaveChanges();


return Json(obj,JsonRequestBehavior.AllowGet);


}





如何添加代码当我删除一行时,我的angularjs控制器调用json?




我尝试过:



我尝试在angularjs中使用$ http来调用json,但我不确定如何在删除angularjs表中的行后使用它。

解决方案

范围,BDetail){ // 在第2部分中解释控制器


scope.budgetdetails = [];

BDetail.GetBDetails()。then(function(d){


scope.budgetdetails = d.data;
});

I have this angularjs controller

 angular.module('MyApp')  //extending angular module from first part
.controller('BudgetAndDetails', function ($scope, BDetail) { //explained    about controller in Part2
   $scope.budgetdetails = [];

   BDetail.GetBDetails().then(function (d) {
    $scope.budgetdetails = d.data;
});


   $scope.removeRow = function (item) {

    var index = $scope.budgetdetails.indexOf(item);
    if (index < 0) {
        $scope.budgetdetails.push(item)

    } else {
        $scope.budgetdetails.splice(index, 1)

    }


};

})



And I have written this json code in my C# controller

[HttpPost]
   public JsonResult update(BudgetandDetails budget)
   {
       var obj = _db.budgets.FirstOrDefault(b => budget.budget.idBudget == b.idBudget);

       _db.budgets.Remove(obj);


       _db.SaveChanges();


       return Json(obj, JsonRequestBehavior.AllowGet);


   }



How do I add the code in my angularjs controller to call the json when I delete a row?


What I have tried:

I have tried using $http in angularjs to call the json but I an not sure how to use it after deleting the row in the angularjs table.

解决方案

scope, BDetail) { //explained about controller in Part2


scope.budgetdetails = []; BDetail.GetBDetails().then(function (d) {


scope.budgetdetails = d.data; });


这篇关于使用jason和angularjs更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆