Reputation:
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;})
Upvotes: 0
Views: 378
Reputation: 428
I am not even sure what exactly you are trying to do but one thing I noticed that is wrong for sure is:
LocationId.GetdataByID()
You have never defined a GetdataById property/method on your LocationId object.
Please provide more information and try to be more clear with what you are trying to do.
Also, you really need to try to format your questions better if you are expecting someone to help you. Reading code is not always easy as it is, and especially not when you don't invest the effort to make it as easy as possible.
Upvotes: 0