I have made a .NET MVC application where I need to send data from frontend to backend. I have created dynamic fields which get added when the user presses the button. But the input added in the dynamic fields is not saved to the database. My backend is on MVC .NET. I want to save the data entered in the dynamic fields.
Html Code:
<div class="form-group">
<label class="col-md-4 control-label"> Phone Number :</label>
<div class="col-md-8">
<input type="text" class="form-control" id="inputLabel3" placeholder="PhnNumber" ng-model="UserContactVM.PhnNumber ">
</div>
<div ng-repeat="UserContactVM in inputs">
<input type="text" ng-model="UserContactVM.v">
</div>
<button ng-click="add()">Add Input</button>
</div>
Javascript:
app.controller("UserController", function ($scope, $http) {
$scope.btntext = "Save";
$scope.inputs = [{ PhnNumber: "" }];
($scope.add = function () {
var dataObj = { PhnNumber: "" };
$scope.inputs.push(dataObj);
}),
($scope.saveuser = function () {
$scope.btntext = "Please Wait..";
$http({
method: "POST",
url: "/User/Create",
datatype: "json",
data: JSON.stringify($scope.UserContactVM),
}).then(
function successCallback(response) {
console.log();
},
function errorCallback(response) {}
);
});
});