Javascript 如何使用angular js为dropdownlist保存id?

Javascript 如何使用angular js为dropdownlist保存id?,javascript,c#,asp.net,angularjs,api,Javascript,C#,Asp.net,Angularjs,Api,我在使用Angularjs的项目中遇到问题。这是我的密码: 控制器 // GET: api/CustomerLists/5 [ResponseType(typeof(CustomerList))] public IHttpActionResult GetCustomerList(int id) { var data = (from cust in db.CustomerLists join call24 in db.

我在使用Angularjs的项目中遇到问题。这是我的密码:

控制器

     // GET: api/CustomerLists/5


    [ResponseType(typeof(CustomerList))]
    public IHttpActionResult GetCustomerList(int id)
    {

        var data = (from cust in db.CustomerLists
            join call24 in db.CallingList4
                on cust.CustID equals call24.CustID

            where cust.CustID == id

            select new CustomerVM
            {
                CustID = cust.CustID,
                Customer = cust.Customer,
                Call4ID = call24.Call4ID,
                Wk1WebID = call24.Wk1WebID,
                Wk1OrdID = call24.Wk1OrdID



            }).First();

        return Ok(data);

    }



  // PUT: api/CustomerLists/5
    [ResponseType(typeof(void))]
    public IHttpActionResult PutCustomerList(CustomerVM vm)
    {

        if (ModelState.IsValid)
        {
            var cust = db.CustomerLists.Find(vm.CustID);
            var call4 = db.CallingList4.Find(vm.Call4ID);

            cust.Customer = vm.Customer;
            cust.ContactName = vm.ContactName;

            call4.Wk1OrdID = vm.Wk1OrdID;
            call4.Wk1WebID = vm.Wk1WebID;


            db.CustomerLists.Attach(cust);
            db.Entry(cust).State = EntityState.Modified;
            db.CallingList4.Attach(call4);
            db.Entry(call4).State = EntityState.Modified;

            db.SaveChanges();
        }


        return StatusCode(HttpStatusCode.NoContent);


    }
JS

  var EditCtrl = function ($scope, $routeParams, $location, data, $http) {

var id = $routeParams.editId;
$scope.lis = data.get({ id: id });

$scope.selectTest = null;
$scope.testTest = [];

$http({
    method: 'GET',
    url: '/api/OrderStatus/',
    data: { OrderStatID: 1 }
}).success(function(result) {
    $scope.testTest = result;
});


$scope.selectTest1 = null;
$scope.testTest1 = [];

$http({
    method: 'GET',
    url: '/api/WebStatus/',
    data: { WebStatID: 1 }
}).success(function (result1) {
    $scope.testTest1 = result1;
});


$scope.save = function () {
    data.update({ id: id }, $scope.lis, function () {
        $location.path('/');
    });
};
模板

<select class="form-control" ng-model="selectTest" ng-model="lis.OrderStatID">
                <option ng-repeat="s in testTest" value="{{s.OrderStatID}}">{{s.OrderStatus}}</option>
            </select>
}

当我尝试更新时,CustomerList详细信息会很好地更新,但是当我选择状态并尝试保存ID时,CallingList4详细信息会返回null。如何将ID从另一个表保存到callingList24主表?请帮忙

已更新

看看这个屏幕截图,它确实从表中选择了,但问题是它不想将id保存到另一个表中


我认为这是一个设计问题,而不是代码问题

您需要重新设计ViewModel,以包含Status和CallingList等属性的子类


然后使用{s.Status.ID}等表达式为所有组合属性传递值

您的描述和代码并不清楚问题出在哪里。例如,角度控制器根本不保存任何内容。发布保存数据的JS和JSON示例,以及该设计在控制器中的作用。查看AngularJS网站上的select示例:它确实保存了。。js中的save方法执行保存操作。。它保存了customerList,但当我试图保存CallingList4时,它保存的下拉列表中的ID为空…@BrianMains请检查我的更新question@mGounda你能帮我吗design@ninjaXnado,我建议你检查一下。这在一个简单的示例中结合了ASP.NET MVC、WebAPI和AngularJS,涵盖了您的案例和更多内容
public class CustomerVM
{
    public int CustID { get; set; }
    public string Customer { get; set; }
    public int? Priority { get; set; }
    public string ContactName { get; set; }
    public string ContactNumber { get; set; }
    public int Call4ID { get; set; }
    public int? Wk1WebID { get; set; }
    public int? Wk1OrdID { get; set; }
    public int? OrderStatId { get; set; }
    public string OrderStatus { get; set; }
}