我使用角度JS MVC这里数据绑定到dropdownlist但是当我尝试将值加载到数据库但该数据没有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;
}
答案 0 :(得分:0)
请查看下面的数据库绑定。
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>
答案 1 :(得分:0)
在select元素中添加ng-if
,问题元素在数据到来之前呈现,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>