如何在使用Angular时从HTML接收Controller中的值 [英] How to receiver value in Controller from HTML while using Angular

查看:55
本文介绍了如何在使用Angular时从HTML接收Controller中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够收到这些值但是你可以看到有一个名为Emp.Id的模型,我被困在这里。在Controller中,实例dailyAttendance没有名为Id的列,但它确实包含EmpId,我应该插入Emp.Id中的值。

请告诉我怎么做。

如果您发现我的问题不清楚,请告诉我。



这是我的观点:



< div ng-app =员工>

< div ng-controller =出勤>

< table id =example2class =table table-bordered table-hover>

< thead>

< tr>

< th>员工姓名< / th>

< th>日期< / th>

< th>状态< / th>

< th>原因(如果有的话)< / th>

< / tr>

< / thead>

< tbody>

< tr ng-repeat =雇员列表中的Emp >

< td> {{Emp.FirstName}}< / td>

< td>

<输入type =hiddenng-model =Emp.Idng - />

< input type =dateng-model =Emp.Date/>

< / td>

< td>

< select ng-model =Emp.Status>

< option>现在< /选项>

< option&g t;缺席< / option>

<选项>半日< /选项>

< / select>

< / td>

< td>

< input type =textng-model =Emp.Reason/>

< / td>



< / tr>

< / tbody>

< tfoot> ;

< tr>

< td>

< input type =submitvalue =保存ng-click = 保存()/>

< / td>

< / tr>

< / tfoot>

< / table>

< / div>

< / div>



这是我的剧本:



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

推荐答案

范围,


http){


scope.employeeList = [];
scope.employeeList = [];


这篇关于如何在使用Angular时从HTML接收Controller中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆