2016-06-14 11 views
0

角度サービスを使用してデータベースからレコードを削除しようとしています。私は私のMVCコントローラでメソッドを作成しましたが、このメソッドを呼び出してidを渡す方法はわかりません。データベースから角度を削除する

 
    [HttpPost] 
     public static void DeleteRecord(int settingID) 
     { 
      try 
      { 
       using (SqlConnection conn = new SqlConnection(connStringApps)) 
       { 
        conn.Open(); 
        using (SqlCommand command = new SqlCommand("DeleteCurrentRecord", conn)) 
        { 
         command.CommandType = System.Data.CommandType.StoredProcedure; 
         command.Parameters.Add("@SettingId", SqlDbType.VarChar).Value = settingID; 
         command.ExecuteNonQuery(); 
         command.Parameters.Clear(); 
        } 
        conn.Close(); 
       } 
      } 
      catch (Exception ex) 
      { 
       Console.Write(ex.ToString()); 
      } 

     } 


     myApp.service("deleteService", function ($rootScope) { 
      this.removeRow = function (recId) { 

      } 
     }); 


     myApp.controller('myController', ['$scope','deleteService', 
      function ($scope, deleteService) { 

       $scope.deleteRecordFromDB = function (recId) { 
        //record id is the Id of the record that I want to delete 
       } 
       ; 
      } 
     ]); 

答えて

3
myApp.service("deleteService", function ($rootScope, $http) { 
     this.removeRow = function (recId) { 

     $http.delete(url, {params: {recordId:recId}}) 
     .success(function (data, status, headers, config) { 
      window.location.reload(); 
     }) 
     .error(function (data, status, header, config) { 
     }); 
     } 
    }); 

    myApp.controller('myController', ['$scope', 'deleteService', function ($scope, deleteService) { 
     $scope.deleteRecordFromDB = function (recId) { 
      deleteService.removeRow(recId); 
     }; 
    } 
    ]); 

あなたは、サーバー側のHTTPGET方法でレコードIDにアクセスすることができます。

+0

ありがとうございます。私はコントローラにサービスを追加するときに何か他のことをする必要がありますか?サーバー側のhttpGetでアクセスする方法を教えてください。 – user6440175

+0

はい。 $ scope.deleteRecordFromDB = function(recId){ deleteService.removeRow(recId);サービスメソッドを呼び出す必要があります。 } ; – rahulbhondave

+0

ありがとうございます。 $ httpが定義されていないというエラーが表示されます。 – user6440175

関連する問題