Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am able to receive the values but as you'll can see there is a model named Emp.Id, I am stuck here. In Controller, the instance dailyAttendance has no such column named as Id,however it do consist EmpId where I am supposed to insert the value which is there in Emp.Id.
Please tell me how to do this.
If you find my question unclear then let me know.

This is my View:

<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.FirstName}}</td>
<td>
<input type="hidden" ng-model="Emp.Id" ng-/>
<input type="date" ng-model="Emp.Date" />
</td>
<td>
<select ng-model="Emp.Status">
<option>Present</option>
<option>Absent</option>
<option>Half-Day</option>
</select>
</td>
<td>
<input type="text" ng-model="Emp.Reason" />
</td>

</tr>
</tbody>
<tfoot>
<tr>
<td>
<input type="submit" value="Save" ng-click="Save()" />
</td>
</tr>
</tfoot>
</table>
</div>
</div>

This is my 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 (employeeList) {
            alert($scope.employeeList);
            $http({
                method: "Post",
                url: "/Attendance/SaveAttendance",
                data: JSON.stringify({ dailyAttendance: $scope.employeeList }),
            }).success(function (data) {
                alert(data);
            }).error(function (err) {
                $scope.Message = err.Message;
            })
        };
    });
</script>


And this is my Controller:

C#
[HttpPost]
        public JsonResult SaveAttendance(List<DailyAttendance> dailyAttendance)
        {
            Response response = new Response();
            foreach (DailyAttendance da in dailyAttendance)
            {
                if (da.Date == null || da.Status == null) continue;
                da.AuthBy = Session["UserName"].ToString();
                dList.Add(da);
            }
            response.Message = attendanceService.SaveAttendance(dList);
            return Json(response.Message, JsonRequestBehavior.AllowGet);
        }
Posted
Comments
[no name] 27-Dec-15 11:56am    
what's the content of DailyAttendance class ?
and can you more clarify your question pls ?
Member 11579819 28-Dec-15 0:35am    
Content of DailyAttendance are: EmpId,Date,Status,Reason.

I have extracted the values from Employee table which consist of Id. And that Id becomes EmpId in DailyAttendance table. Now the problem is the values i send from angular to controller doesn't have any column name like EmpId. So the controller could not receive the value of EmpId.

1 solution

what i understand from your code :
you load list of Employee, you do the bind of your row (Employee object ) thanks to angular. after modification you call save method.
In this case you manipulate only Employee object.

You must verify if your "/Attendance/Details" service return a list of DailyAttendance not of Employee.

and in angular mapping (ng-model), you must use the same fields of DailyAttendance class.

I hope that help you, else you can show me the implementation of /Attendance/Details service .
 
Share this answer
 

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