我想通过jsonresult获取dropdownlist索引来交互数据库,但是当我更改下拉列表时没有生成任何操作,这里是代码。
(function () {
//Create a Module
var app = angular.module('MyApp', ['ngRoute']); // Will use ['ng-Route']
//implement routing
})();
获取下拉列表索引的代码
angular.module('MyApp').controller('CommandeControllerClt', function ($scope, LocationService) {
$scope.Id_Partenaire = null;
$scope.PartenaireList = null;
// Function For Populate partnerers
$scope.GetPartenaire = function () {
//Load State
LocationService.GetPartenaire($scope.Id_Partenaire).then(function (d) {
alert(d.data);
}, function (error) {
alert('Error!');
});
}
})
.factory('LocationService', function ($http) { // explained about factory in Part2
var fac = {};
fac.GetPartenaire = function (Id_Partenaire) {
return $http.get('/CommandeClt/GetPartenaire?Id_CltOrigine=' + Id_Partenaire)
}
return fac;
});
jsonResult
public JsonResult GetPartenaire(int Id_CltOrigine)
{
var Nom_CltOrigine = MetiersRepository.ClientSearch(Id_CltOrigine).Select(s => new Partenaire() { Cd_Partenaire = s.Cd_Partenaire, Adresse_Societe = s.Adresse_Societe }).ToList();
return new JsonResult { Data = Nom_CltOrigine, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
Code Rezor,下拉列表已经绑定
<select name="Id_Partenaire" ng-model="Id_Partenaire"
ng-options="I.Id_Partenaire as I.Cd_Partenaire for I in PartenaireList"
ng-change="GetState()">
@{
foreach (var c in ViewBag.SelectedClientOption)
{
<option value="@c.Id_Partenaire">@c.Cd_Partenaire</option>
}
}
</select>