Click here to Skip to main content
14,700,041 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">
<th>Employee Name</th>
<th>Reason(if any)</th>
<tr ng-repeat="Emp in employeeList">
<input type="hidden" ng-model="Emp.Id" ng-/>
<input type="date" ng-model="Emp.Date" />
<select ng-model="Emp.Status">
<input type="text" ng-model="Emp.Reason" />

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

This is my Script:

<script type="text/javascript">
    var Employee = angular.module("Employee", []);
    Employee.controller("Attendance", function ($scope, $http) {
        $scope.employeeList = [];
            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) {
                method: "Post",
                url: "/Attendance/SaveAttendance",
                data: JSON.stringify({ dailyAttendance: $scope.employeeList }),
            }).success(function (data) {
            }).error(function (err) {
                $scope.Message = err.Message;

And this is my Controller:

        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();
            response.Message = attendanceService.SaveAttendance(dList);
            return Json(response.Message, JsonRequestBehavior.AllowGet);
Omar Nasri 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 .

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