title: How to save and edit data using dropdownlist in asp.net core mvc using angular js
body: <p>I am using AngularJs in small part of my asp.net core MVC project i am using two dropdownlist and a textbox using textbox i am able to save and edit data but with dropdownlist i am not able to reset dropdownlist after posting the data also i am not able to edit the record with dropdowns.</p>
  <p>Here is my code</p>
  <pre><code>&lt;table ng-table=&quot;tblCustomers&quot; class=&quot;table&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Stakes&lt;/th&gt;
                      &lt;th&gt;Supplier&lt;/th&gt;
                      &lt;th&gt;Description&lt;/th&gt;
                      &lt;th&gt;&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;tbody ng-repeat=&quot;m in ST&quot;&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;span ng-hide=&quot;m.EditMode&quot;&gt;{{m.stakeName}}&lt;/span&gt;
                              &lt;select ng-model=&quot;StakeId&quot; value=&quot;{{ m.stakeId }}&quot; ng-options=&quot;s.stakeName for s in StakeList track by s.stakeId&quot; ng-show=&quot;m.EditMode&quot; class=&quot;form-control&quot;&gt;
                                  &lt;option value=&quot;&quot;&gt;Select Stake&lt;/option&gt;
                              &lt;/select&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;span ng-hide=&quot;m.EditMode&quot;&gt;{{m.supplierName}}&lt;/span&gt;
                              &lt;select ng-model=&quot;SupplierId&quot; value=&quot;{{ m.supplierId }}&quot; ng-options=&quot;a.supplierName for a in SupplierList track by a.supplierId&quot; ng-show=&quot;m.EditMode&quot; class=&quot;form-control&quot;&gt;
                                  &lt;option value=&quot;&quot;&gt;Select Supplier&lt;/option&gt;
                              &lt;/select&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;span ng-hide=&quot;m.EditMode&quot;&gt;{{m.description}}&lt;/span&gt;
                              &lt;input type=&quot;text&quot; ng-model=&quot;m.description&quot; ng-show=&quot;m.EditMode&quot; /&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;a class=&quot;Edit&quot; href=&quot;javascript:;&quot; ng-hide=&quot;m.EditMode&quot; ng-model=&quot;m.stakeTransId&quot; ng-click=&quot;Edit($index)&quot;&gt;Edit&lt;/a&gt;
                              &lt;a class=&quot;Update&quot; href=&quot;javascript:;&quot; ng-show=&quot;m.EditMode&quot; ng-click=&quot;Update($index)&quot;&gt;Update&lt;/a&gt;
                              &lt;a class=&quot;Cancel&quot; href=&quot;javascript:;&quot; ng-show=&quot;m.EditMode&quot; ng-click=&quot;Cancel($index)&quot;&gt;Cancel&lt;/a&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
              &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                              &lt;select ng-model=&quot;StakeId&quot; value=&quot;{{ m.stakeId }}&quot; ng-options=&quot;s.stakeName for s in StakeList track by s.stakeId&quot; ng-show=&quot;m.EditMode&quot; class=&quot;form-control&quot;&gt;
                                  &lt;option value=&quot;&quot;&gt;Select Share&lt;/option&gt;
                              &lt;/select&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                              &lt;select ng-model=&quot;SupplierId&quot; value=&quot;{{ m.supplierId }}&quot; ng-options=&quot;a.supplierName for a in SupplierList track by a.supplierId&quot; ng-show=&quot;m.EditMode&quot; class=&quot;form-control&quot;&gt;
                                  &lt;option value=&quot;&quot;&gt;Select Agent&lt;/option&gt;
                              &lt;/select&gt;
                      &lt;/td&gt;
  
                      &lt;td width=&quot;150px&quot;&gt;
                          &lt;input ng-model=&quot;Description&quot; placeholder=&quot;Description&quot; class=&quot;form-control&quot; /&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type=&quot;button&quot; value=&quot;Add&quot; id=&quot;Save&quot; ng-click=&quot;Savedata()&quot; /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
  </code></pre>
  <p>Here is my controller code</p>
  <pre><code>[HttpPost]
      public JsonResult AddStakeTrans(int supplierId, int stakeId, string desc)
      {
          StakeTran stakeTrans = new StakeTran();
          shareTrans.SupplierId = supplierId;
          shareTrans.StakeId = stakeId;
          shareTrans.Description = desc;
          db.Insert(stakeTrans);
      
      //after posting data to get inserted record to display in table 
      StakeTransViewModel stakeTransViewModel = new StakeTransViewModel();
      stakeTransViewModel.SupplierName = db.ExecuteScalar&lt;string&gt;(&quot;Select SupplierName from Supplier where SupplierId = @0&quot;, supplierId);
      stakeTransViewModel.StakeName = db.ExecuteScalar&lt;string&gt;(&quot;Select StakeName from Stake where StakeId = @0&quot;, stakeId);
      stakeTransViewModel.Description = desc;
      
      //to get the dropdownlist 
      stakeTransViewModel.StakeList = db.Fetch&lt;Stake&gt;(&quot;Select StakeId,StakeName from Share&quot;).ToList();
      stakeTransViewModel.SupplierList = db.Fetch&lt;Supplier&gt;(&quot;Select SupplierId,SupplierId from Supplier&quot;).ToList();
      return Json(stakeTransViewModel);
  }
  </code></pre>
  <p>Here is my angular code to post and edit data</p>
  <pre><code>        $scope.StakeList = &quot;&quot;;
          $scope.SupplierList = &quot;&quot;;
          $scope.Savedata = function () {
              $http({
                  method: &quot;POST&quot;,
                  url: &quot;/StakeTrans/AddStakeTrans&quot;,
                  data: $.param({
                      supplierId: $scope.SupplierId.supplierId,
                      stakeId: $scope.StakeId.stakeId,
                      desc: $scope.Description
                  }),
                  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
              }).then(function (data) {
                  $scope.ST.StakeName = data.data.StakeName;
                  $scope.ST.SupplierName = data.data.SupplierName;
                  $scope.StakeList = data.data.stakeList;
                  $scope.SupplierList = data.data.supplierList;
                  $scope.StakeId = data.data.stakeList;
                  $scope.SupplierId = data.data.supplierList;
                  $scope.ST.push(data.data);
                  $scope.btntext = &quot;Save&quot;;
              },function (error) {
  
              });
              $scope.StakeTransId = &quot;&quot;;
              $scope.StakeId = &quot;&quot;;
              $scope.StakeName = &quot;&quot;;
              $scope.SupplierId = &quot;&quot;;
              $scope.SupplierName = &quot;&quot;;
              $scope.Description = &quot;&quot;;
  
          };
  
  
  
  
          //This variable is used to store the original values.
          $scope.EditItem = {};
  
          //Editing an existing record.
          $scope.Edit = function (index) {
  
              $scope.ST[index].EditMode = true;
  
              $scope.EditItem.stakeId = $scope.ST[index].StakeId.stakeId;
              $scope.EditItem.supplierId = $scope.ST[index].SupplierId.supplierId;
              $scope.EditItem.description = $scope.ST[index].description;
  
  
  //the update code
          };
  </code></pre>
  <p>in edit mode i want to hide the data in the row besides which i have edit button and show textbox and dropdown with value which that particular id have just like we normally have in edit mode and then want to click on update to update the record also in add mode when i click on add button the record get added and shown in the grid successfully but my dropdownlists are not getting reset.</p>
  <p>So this is the whole problem i am facing and i am not getting the solution for that, can anybody suggest me the solution to how i can successfully get dropdownlist working in add and edit mode using angular js.</p>