【发布时间】:2015-02-11 04:45:40
【问题描述】:
我在使用 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>
查看模型
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; }
}
}
当我尝试更新时,CustomerList 详细信息更新得很好,但是当我选择状态并尝试保存 ID 时,CallingList4 详细信息返回 null。如何将 ID 从另一个表保存到调用List24 的主表中?请帮忙
更新
看看这个屏幕截图,它确实从表中选择,但问题是它不想将 id 保存到另一个表。
【问题讨论】:
-
从您的描述和代码中并不清楚问题出在哪里。例如,您的角度控制器根本不保存任何东西。将保存数据的 JS 和 JSON 的示例以及它反序列化到您的控制器中。
-
查看 AngularJS 网站上的选择示例:docs.angularjs.org/api/ng/directive/select
-
它确实保存了.. js 中的保存方法进行了保存.. 它保存了 customerList 但是当我尝试保存 CallingList4 时,下拉列表中的 ID 保存为空...跨度>
-
@BrianMains 请检查我更新的问题
标签: javascript c# asp.net angularjs api