【发布时间】:2016-11-04 08:03:20
【问题描述】:
public JsonResult GetdataByID(int Id) { var x = (来自 db.Employees 中的 n 其中 n.Id == Id 选择 n).FirstOrDefault(); 返回新的 JsonResult { 数据 = x,JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
public JsonResult GetCountries()
{
List<Employee> allCountry = new List<Employee>();
using (WorkdbEntities dc = new WorkdbEntities())
{
allCountry = dc.Employees.OrderBy(a => a.Id).ToList();
}
return new JsonResult { Data = allCountry, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
HTML 代码
<div ng-controller="BindData">
<select ng-model="Id" ng-options="I.Id as I.Id for I in BindId" ng-change="GetState()">
<option value="">Select Id</option>
</select>
<table>
<tr>
<td>Employeename</td>
</tr>
<tr ng-repeat="ff in BindTable">
<td>
{{ff.Name}}
</td>
</tr>
</table>
</div>
控制器代码
angular.module("MyApp")
.controller("BindData", function ($scope, LocationId) {
$scope.BindId = null;
$scope.Id = null;
LocationId.GetCountries()
.then(function (d) {
$scope.BindId = d.data;})$scope.GetState = function (Employee) {LocationId.GetdataByID($scope.Id).then(function (d) $scope.BindTable = d.data;})}})
工厂代码
.factory("LocationId", function ($http) {
var fac = {};
fac.GetCountries = function () {
return $http.get("/Home/GetCountries")
}
fac.GetState = function (Id) {
return $http.get("Home/GetdataByID ? Id=" + Id)
}
return fac;})
【问题讨论】:
标签: angularjs asp.net-mvc