This is the code for binding the values into the drop down using angular
HTML CODE:
<div class="form-group">
<label class="control-label col-md-4">State</label>
<div class="col-md-8">
<select class="form-control" ng-model="model.StateId" ng-options="item.StateId as item.StateName for item in states"> <option value="">--Select State--</option> </select>
</div>
</div>
Angular code:
$scope.states = [];
$http({
method: 'GET',
url: 'GetStates',
}).success(function (result) {
$scope.states = result;
});
.CS CODE
public JsonResult GetStates()
{
ApplicationDbContext _db = new ApplicationDbContext();
return Json(_db.States.Select(c => new { StateId = c.StateId, StateName = c.StateName }), JsonRequestBehavior.AllowGet);
}
HTML CODE:
<div class="form-group">
<label class="control-label col-md-4">State</label>
<div class="col-md-8">
<select class="form-control" ng-model="model.StateId" ng-options="item.StateId as item.StateName for item in states"> <option value="">--Select State--</option> </select>
</div>
</div>
Angular code:
$scope.states = [];
$http({
method: 'GET',
url: 'GetStates',
}).success(function (result) {
$scope.states = result;
});
.CS CODE
public JsonResult GetStates()
{
ApplicationDbContext _db = new ApplicationDbContext();
return Json(_db.States.Select(c => new { StateId = c.StateId, StateName = c.StateName }), JsonRequestBehavior.AllowGet);
}