Click here to Skip to main content
15,916,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am unable to post multiple rows on single of a button. Neither I could see the values of those multiple rows in Alert.Below are my HTML and script code. Please HELP!!!

This is my HTML:-
HTML
<div ng-app="Employee">
                        <div ng-controller="Attendance">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>Employee Name</th>
                                        <th>Date</th>
                                        <th>Status</th>
                                        <th>Reason(if any)</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="Emp in employeeList">
                                        <td>{{Emp.Name}}</td>
                                        <td>
                                            <input type="hidden" ng-model="Emp.Id" />
                                            <input type="date" ng-model="Emp.Date" />
                                        </td>
                                        <td>
                                            <select ng-model="Emp.Status">
                                                <option ng-repeat="DDL in dropDownList">{{DDL}}</option>
                                            </select>
                                        </td>
                                        <td>
                                            <input type="text" ng-model="Emp.Reason" />
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
<input type="submit" value="Save" ng-click="Save(Emp)" />


And my Angular Script:
HTML
<script type="text/javascript">
    var Employee = angular.module("Employee", []);
    Employee.controller("Attendance", function ($scope, $http) {
        $scope.employeeList = [];
        $http({
            method: "GET",
            url: "/Attendance/Details",
        }).success(function (data) {
            $scope.employeeList = data.a;
            $scope.dropDownList = data.b;
        }).error(function (error) {
            $scope.Message = error.Message;
        })
        $scope.Save = function () {
            alert(JSON.stringify(Emp));
            $http({
                method: "Post",
                url: "/Attendance/SaveAttendance1",
                data: JSON.stringify(Emp),
            }).success(function (data) {
                alert(data);
            }).error(function (err) {
                $scope.Message = err.Message;
            })
        };
    });
</script>
Posted
Updated 20-Dec-15 19:10pm
v2
Comments
Member 11579819 20-Dec-15 11:13am    
I missed the button in html.

<input type="submit" value="Save" ng-click="Save(Emp)" />

1 solution

JavaScript
Use $scope.employeeList variable to post data beacuse Emp variable is not exist in scope. Remove Emp parameter on Save button click method.

<input type="submit" value="Save" ng-click="Save()" />

<script type="text/javascript">
    var Employee = angular.module("Employee", []);
    Employee.controller("Attendance", function ($scope, $http) {
        $scope.employeeList = [];
        $http({
            method: "GET",
            url: "/Attendance/Details",
        }).success(function (data) {
            $scope.employeeList = data.a;
            $scope.dropDownList = data.b;
        }).error(function (error) {
            $scope.Message = error.Message;
        })
        $scope.Save = function () {
            alert(JSON.stringify($scope.employeeList));
            $http({
                method: "Post",
                url: "/Attendance/SaveAttendance1",
                data: $scope.employeeList,
            }).success(function (data) {
                alert(data);
            }).error(function (err) {
                $scope.Message = err.Message;
            })
        };
    });
</script>

Hopefully it will work ...!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900