我无法将正确的ID发送到我的修改方法

时间:2015-10-15 13:02:28

标签: angularjs asp.net-mvc

当我尝试从表中修改行时,我的代码有问题,我使用AngularJS作为客户端,ASP.Net作为其余API,这是我的API修改代码:

[Route("api/Students/modifier/{id}")]
        public async Task<HttpResponseMessage> PUT(int id, Student value)
        {
            try
            {
                _StudentService.Update(value);
                await _unitOfWorkAsync.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
            return Request.CreateResponse(HttpStatusCode.OK);
        }

这是我的HTML代码:

    <table class="table table-responsive table-hover" ng-controller="etudmodifCtrl">
<thead>
</thead>
 <tbody >
 <tr ng-repeat="store in currentPageStores>
       <td align="center">{{store.LastName}}</td>
       <td align="center">{{store.FirstName}}</td>
       <td align="center">{{store.Email}}</td> 
       <td align="center" ng-controller="etuddeleteCtrl">
          <div id="myModal" class="modal fade" role="dialog" >
            <div class="modal-dialog">
              <div class="modal-content">
                <div class="modal-header">....</div>
                <div class="modal-body">
                       <div class="form-group">
                         <label>LastName</label>
                            <div class="col-sm-10">
                 <input type="text" class="form-control"  ng-model="nomet">
                            </div>
                        </div>
                        <div class="form-group">
                         <label>FirstName</label>
                            <div class="col-sm-10">
               <input type="text" class="form-control"  ng-model="prenomet">
                            </div>
                        </div>
                        <div class="form-group">
                         <label>Email</label>
                            <div class="col-sm-10">
             <input type="text" class="form-control"  ng-model="email">
                            </div>
                        </div>
                </div>
                <div class="modal-footer">
                   <button ng-click="modifetud(store.$id)">OK</button>
                </div>
            </div>  
        </div>
     //this button opens the modal in which I will modify the data
         <button ng-click="open(store.$id)" data-target="#myModal">Modify</button>
        </td>
    </tr></tbody></table>   

控制器:

    .controller("etudmodifCtrl", ["$scope", "$http", function ($scope, $http) {

     //I get the data via these method and a correct Id of the selected row
                  $scope.open = function ($id) {$http(
                    {method: 'GET', url:'http://localhost:50001/api/Students/'+$id})
                         .success(......)
                             .error 
                                   }
  $scope.modifetud = function ($id) {$http(
{method: 'PUT',url:'http://localhost:50001/api/Students/modifier/'+$id,data:'{"FirstName":"'+$scope.prenomet+'","LastName":"'+$scope.nomet+'","Email"'+$scope.email+'"}'}                                                            
       )}       
    })

问题是删除工作正常,并且对于etudmodifCtrl控制器,我从表中选择了正确的Id,并且我已正确地将其发送到模态。我的问题是当我点击按钮&#34; OK&#34;对于模态,它始终显示id=1和旧数据(修改前的数据)。 例如,我选择了ID为12的行,然后点击按钮&#34; OK&#34;在模态中,这是我在调试时得到的:

enter image description here

从浏览器请求详细信息

enter image description here

0 个答案:

没有答案