2016-08-16 112 views
0

在我的ASP.Net/MVC应用程序中,我使用AngularJS来显示数据库中的记录列表。当我更新记录时,在刷新页面之前它不会在视图(html)中更新?更改不会自动出现在视图中(AngularJS更新)

的观点:

<tr ng-repeat="bu in bus"> 
    <td>{{bu.BU_Name}}</a></td> 
    <td>{{bu.BU_Info}}</a></td> 
    <th><a href="javascript:void(0)" ng-click="editItem(bu)">Del</a></th> 
</tr> 

的JS:

$scope.editItem= function (bu) { 
    $http.post('/CO/DelBU', {dbunt: bu}) 
    .then(function (response) { 
     $scope.bus = response.data; 
    }) 
    .catch(function (e) { 
     console.log("error", e); 
     throw e; 
    }) 
    .finally(function() { 
     console.log("This finally block"); 
    }); 
}; 

的MVC控制器:

[HttpPost] 
    public JsonResult DelBU(BUs dbunt) 
    { 
     var db = new scaleDBEntities(); 
     var burecord = db.Buses.Find(dbunt.BU_ID); 
     db.Database.ExecuteSqlCommand("UPDATE dbo.BUs SET BU_Name='just a test'"); 
     var burecords = db.Buses.ToList(); 
     return Json(burecords, JsonRequestBehavior.AllowGet); 
    } 

所以,当我点击编辑,名称不会改变屏幕除非我刷新页面!我怎样才能解决这个问题?

谢谢

+0

你有没有调试行:$ scope.bus = response.data;确保你获得名单? – cullimorer

+0

嗯,我会说是的,因为当我第一次显示数据库中的数据时,我的http.get中使用了相同的行。 –

+0

但是,您没有使用POST函数获取所有数据....两个调用必然是相互独立的? – cullimorer

回答

-1

我认为你需要设置公交手表 - 在这里看到更多的细节:

How do I use $scope.$watch and $scope.$apply in AngularJS?

+0

汤姆,如果可能的话,你会解释一下如何在我的代码中使用$ watch吗?谢谢 –

+0

Angular会自动创建$ watch,因为它使用角度{{}}语法 – Shaggy13spe

+0

绑定,因为总线中的

相关问题