【发布时间】:2018-05-08 16:32:18
【问题描述】:
我想将 cod 发送到控制器并返回数组
按下li 时,您必须向控制器发送代码,在这种情况下,我设置了示例 7。代码到达控制器后,我将有一个列表,我必须在 ng 中显示- 在表中重复
脚本
<script type="text/javascript">
var app = angular.module('myApp', [])
app.value('studentInfo', [
{ id: 1, name: 'Mahedee Hasan', credit: 20, semester: '8th' },
{ id: 3, name: 'Enamul Haque', credit: 15, semester: '7th' }
]);
app.controller('myCtrl', ['$scope', 'studentInfo', function ($scope, studentInfo, $http, $window) {
$scope.myClickList = function () {
$scope.studentInfo = studentInfo;
};
var Cod = "7";
$scope.myDataCountry = [];
$scope.ButtonCountry = function (Cod) {
$http.
post("/Country/Angular", { CodH: Cod }).success(function (result) {
$scope.myDataCountry = result;
});
};
}]
);
</script>
查看
<li><a data-toggle="tab" href="#calificaciones" ng-click="ButtonCountry ()"><span>Country</span></a></li>
<div ng-app="myApp" ng-controller="myCtrl">
<table class="table">
<tr>
<th>ID</th>
<th>Country</th>
</tr>
<tr ng-repeat="C in myDataCountry">
<td>{{C.ID}}</td>
<td>{{C.Country}}</td>
</tr>
</table>
</div>
控制器
public JsonResult Angular(string codCountry)
{
var country = (from a in dbCountry.Country
where a.CodPersona == codCountry
select a.Country).ToList();
return Json(country , JsonRequestBehavior.AllowGet);
}
【问题讨论】:
-
ng-click位于控制器范围之外的元素上。控制器的内联数组注解与依赖注入不匹配。 -
.success方法是deprecated and removed from V1.6。 -
您的 MVC 控制器的名称是什么?是 CountryController 吗?
标签: asp.net angularjs asp.net-mvc angularjs-ng-repeat angularjs-ng-click