Я использую угловой JS MVC, здесь данные привязаны к выпадающему списку, но когда я пытаюсь загрузить значение в базу данных, но эти данные не binfing:
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left:20px">
<b>State</b>
</div>
<div class="col-md-8 col-sm-8">
<select class="form-control" data-modal="modal" ng-options="I.CountryID as I.CountryName for I in CountryList" ng-model="CountryID" ng-change="StateList()" ng-required="true">
<option value="" disabled selected>--Select Country--</option>
</div>
</div>
</div>
угловой код
$scope.AddUpdateEmployee = function (Emp) {
alert("Enter in update")
var Employee = {
Id: $scope.EmployeeId,
Name: $scope.EmployeeName,
Email: $scope.EmployeeEmail,
Psw: $scope.Password,
Country: $scope.CountryID,
};
код mvc
public JsonResult AddEmployee( Employee emps)
{
if (emps != null)
{
Employee ee = new Employee();
ee.Name = emps.Name;
ee.Email = emps.Email;
ee.Psw = emps.Psw;
ee.Country = emps.Country;
ee.State = emps.State;
ee.City = emps.City;
}
Добавьте элемент ng-if
в элементе select, элемент проблемы будет отображаться до того, как данные придут, ng-if
устанавливает часы на нем
<select ng-if="CountryList && CountryList.length" class="form-control" data-modal="modal" ng-options="I.CountryID as I.CountryName for I in CountryList" ng-model="CountryID" ng-change="StateList()" ng-required="true">
<option value="" disabled selected>--Select Country--</option>
</select>
Пожалуйста, проверьте ниже, его привязка из базы данных.
http://jsfiddle.net/81t6cbjw/261/
<select class="form-control" data-modal="modal"
ng-options="I.CountryID as I.CountryName for I in CountryList"
ng-model="CountryID" ng-change="StateList()" ng-required="true">
<option value="" disabled selected>--Select Country--</option>
</select>