简体   繁体   中英

Select option passing null to database

I have a view as below:

<select ng-model="d" ng-options="k.id as k.name for k in act"></select>
<input type="submit" value="Create" ng-click="CreateOpen(Emp)" class="btn btn-default" />
</div>

My Js is as below:

app.factory('crudServiceUser', function ($http) {
    crudUserObj = {};
  crudUserObj.Create = function (openact) {
        var Emp;
        Emp = $http({
            method: 'Post',
            url: '/Employee/BankAccount/Index',
            data: openact
        }
        ).then(function (response) {
            return response.data;
        });
        return Emp;
    }
return crudUserObj;
});

app.controller('usersController', function ($scope, crudServiceUser) {
 $scope.CreateOpen = function (openact) {
        crudServiceUser.Create(openact).then(function (result) {

            $scope.Msg = alert(result.EName + " Has Been Created Successfully");

        })
    }

Here is my action method:

public ActionResult Index(tblOpenAct tblopact)
        {            
          if (ModelState.IsValid)
          {                
           objemp.OpenActBs.Insert(tblopact);  
           return RedirectToAction("Index");

          }                
        return View(tblopact);        

       }

But the select option is inserting null to database but if I use textbox then it inserts data.

Try like bellow

<select ng-model="d" >
<option ng-repeat="k in act" value="{{k.id}}">{{k.name }}     </option>
</select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM