public JsonResult GetdataByID(int Id) { var x = (from n in db.Employees where n.Id == Id select n).FirstOrDefault(); return new JsonResult { Data = 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 Code
<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>
Controller Code
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 Code
.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;})