因此,我目前正在使用WebAPI和AngularJS從SQL表中搜索一些數據並將其顯示在網頁上以供用戶選擇多個單獨的數據行。我將選定的行插入單獨的JSON數組(可用的客戶端),我想將其插入到單獨的SQL表中。使用我的JSON數據數組並將其插入到不同的SQL表中的最佳方法是什麼?我將附上我目前用來獲取數據的代碼。如何將AngularJS JSON數據插入SQL
Controller.js
var app = angular.module('myApp', []);
app.controller("myController", function ($scope, $http) {
function getCert(myid) {
$http.get('api/Cert/Get/', { params: { id : myid } })
.success(function (data) {
$scope.selectedclients = data;
})
}
$scope.searchClick = function() {
getCert($scope.myid);
}
$scope.moveItem = function (item, from, to) {
var idx = from.indexOf(item);
if (idx != -1) {
from.splice(idx, 1);
to.push(item);
}
};
$scope.availableclients = [];
});
HTML
<html data-ng-app="myApp">
<body data-ng-controller ="myController">
My_ID: <input type="text" ng-model="my_id" />
<input type="submit" value="Search" ng-click="searchClick()" />
<select size="10" multiple ng-model="selected" ng-options="i.unit_id for i in selectedclients" style="width: 400px"></select>
<div class="btn-group">
<button title="Remove From List" class="btn btn-default" ng-click="moveItem(available[0], availableclients,selectedclients)"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button title="Add To List" class="btn btn-default" ng-click="moveItem(selected[0], selectedclients,availableclients)"><i class="glyphicon glyphicon-chevron-right"></i></button>
</div>
<select size="10" multiple ng-model="available" ng-options="i.unit_id for i in availableclients" style="width: 400px"></select>
</body>
</html>
我有工作正常的代碼我只是在爲如何把我的availableclients JSON陣列和插入損耗到我的SQL表中。這可能很容易做到,但是我所有的搜索都在我正在尋找的內容上空白。任何幫助表示讚賞。謝謝!
編輯1:在評論的建議我添加我用於Web API獲取的控制器。再次感謝您的任何建議!
public class CertController : ApiController
{
CertEntities objapi = new CertEntities();
[HttpGet]
public IEnumerable<AngularCoCSelect_Result> Get(int id)
{
return objapi.AngularCoCSelect(id).AsEnumerable();
}
}
我使用實體框架和Web API來獲取我的數據。我會更新並將其添加到我原來的帖子中。 – dev53
所以你的問題是如何從角度做到這一點,如何將數據發送到web api? – eesdil
是的,我想這就是我正在尋找的!正如其他人所評論的,如果我正確理解這一點,我可以使用put/push將它發送到Web API。 – dev53