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:
<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:
[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);
}