我有一个AngularJS代码
function helperController($scope, $http) {
console.log("entering the controller");
var baseUrl = "http://localhost:8000/api";
//schools
var getSchools = function (result) {
console.log("getting schools");
if (result != []) {
$scope.schools = result;
} else {
$scope.schools = null;
}
};
var onError = function (reason) {
console.log(reason);
$scope.error = "No schools seeding information";
};
console.log($scope.schoolId);
$http({
url: baseUrl + "/schools",
type: "GET",
contentType: "application/json",
})
.success(function (result) {
console.log(result);
getSchools(result);
}).error(function (reason) {
onError(reason);
});
//getting states
//get the country where country name is nigeria
$http({
url: baseUrl + "/countries",
type: "GET",
contentType: "application/json",
params: { countryId: 160 },
}).success(function (result) {
$scope.NigeriaID = result.NigeriaID;
}).error(function (reason) {
console.log("cannot get Nigeria ID ");
});
var getStates = function (result) {
console.log(result);
$scope.states = result;
};
var errorGettingStates = function (reason) {
console.log("cannot get states" + reason);
};
$http({
url: baseUrl + "/states",
type: "GET",
contentType: "application/json",
params: { id: $scope.NigeriaID }
}).success(function (result) {
console.log("getting countries");
getStates(result);
}).error(function (reason) {
errorGettingStates(reason);
});
}此代码正确地从托管api中获取学校和国家。
这是我的.chtml页面
<div class="form-group">
@Html.LabelFor(model => model.SchoolID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*<select data-ng-model="selectedState" class="form-control">
<option data-ng-repeat="school in schools" value="{{school.id}}">{{school.name}}</option>
</select>*@
@Html.DropDownListFor(model => model.SchoolID,new SelectList("select school"),"Select School",
new
{
@class = "form-control",
@ng_model = "schoolId",
@ng_options = "s.id as s.name for s in schools",
})
@Html.ValidationMessageFor(model => model.SchoolID, "", new { @class = "text-danger" })
<label id="lab1">{{SchoolId}}</label>
</div>
</div>表单中的第一个值是“School”,其他值是从数据库中填充的。当我选择下一个值时,例如如果下拉列表包含以下值
如果我选择“生物化学实验学校”并提交表格,下拉式的值应该是1,但我得到的是0。
帮帮忙,我做错什么了?
发布于 2015-04-21 13:25:05
<select data-ng-model="person.MaritalStatus" name="MaritalStatus" >
<option value="9999">-- Select Marital Status --</option>
<option ng-repeat="c in MaritalStatu" value="{{c.MaritalStatus}}">{{c.MaritalStatus}}</option>
</select> 尝试以上方法,替换您自己的变量。
https://stackoverflow.com/questions/29754442
复制相似问题