3

I want to bind dropdowns in edit mode but with value selected according to each record

My Edit View

<select ng-model="user.StateId" ng-init="user.StateId=@Model.StateId" data-ng-options="s.Id as s.State for s in States " data-ngchange="GetCities()"></select>

  <select ng-model="user.CityId"  data-ng-options="c.Id as c.City for c in Cities " ></select>

My Angular Js

 function GetStates() {

              $http({
                  method: 'Get',
                  url: '/Home/GetStates'
              }).success(function (data, status, headers, config) {
                  $scope.States = data;

              }).error(function (data, status, headers, config) {
                  $scope.message = 'Unexpected Error';
              });
          }

          $scope.GetCities = function (obj) {

              var stateId = $scope.user.StateId;
              alert(stateId);
              if (stateId) {
                  $http({
                      method: 'POST',
                      url: '/Home/GetCities/',
                      data: JSON.stringify({ stateId: stateId })
                  }).success(function (data, status, headers, config) {
                      $scope.Cities = data;
                  }).error(function (data, status, headers, config) {
                      $scope.message = 'Unexpected Error';
                  });


              }
              else {
                  $scope.states = null;
              }
          }

  $scope.edit = function (user) {            
              var ref = user;
              $http
              ({
                  method: 'GET',
                  dataType: 'html',
                  url: location.href = '../Home/Edit?Id=' + ref.Id,

              })
          }

Now when user click on edit i want to open user details in edit mode and i m doing so using $scope.edit user is my object in which i m getting data to edit now i want dropdown of edit view to show state and city selected as per the state and city i got as a response in function(user)

0 Answers0