JS File
var module = angular.module('myApp', []);
module.controller('myController', function ($scope, $http) {
$scope.items = [{}];
$scope.users = {};
$scope.addfield = function () {
$scope.items.push({});
}
$scope.saveUser = function () {
$scope.results = [];
console.log($scope.users);
$http({
method: 'POST',
url: '/Data/MethodTest',
data:{
users: $scope.users
}
}).success(function (data) {
console.log(data)
});
}
});
HTML Code
<body data-ng-app="myApp" data-ng-controller="myController">
<form name="educdetailsform" novalidate>
<label>Education Details</label></br>
<button ng-click="addfield()">Add Education</button>
<div ng-repeat="item in items track by $index">
<input type="text" name="empData.qualification[]" placeholder="Qualification" ng-model="users[$index].qualification">
<input type="text" name="empData.year[]" placeholder="Year of Passing" ng-model="users[$index].year">
<input type="text" name="empData.percentage[]" placeholder="Percentage" ng-model="users[$index].percentage">
</div>
<input type="submit" name="submit" ng-click="saveUser()" />
</form>
</div>
</body>
.cs Code // I'm trying to insert values of the object fetched into database. Before which I've just written code to deserialise the objects. as of now I'm getting just null values passed from the JS//
public JsonResult MethodTest(string jsonData)
{
string jdata = jsonData.ToString();
List<StockAllocate> stockData;
bool status = false;
JavaScriptSerializer jss = new JavaScriptSerializer();
stockData = jss.Deserialize<List<StockAllocate>>(jdata);
status = true;
return new JsonResult { Data = new { status = status } };
}