Asp.net mvc 将对象从AngularJS传递到ASP.NET MVC控制器
我试图从AngularJS向我的MVC控制器传递一些数据,但是MVC控制器上的Customer对象总是空的。我错过了什么 棱角分明Asp.net mvc 将对象从AngularJS传递到ASP.NET MVC控制器,asp.net-mvc,angularjs,Asp.net Mvc,Angularjs,我试图从AngularJS向我的MVC控制器传递一些数据,但是MVC控制器上的Customer对象总是空的。我错过了什么 棱角分明 $scope.new = {}; $scope.AddCustomer = function () { $http.post('/Customer/SaveCustomer', $scope.new).success(function () { }); } HTML <input
$scope.new = {};
$scope.AddCustomer = function () {
$http.post('/Customer/SaveCustomer', $scope.new).success(function () {
});
}
HTML
<input class="form-control" type="text" placeholder="CustomerID" ng-model="new.c.CustomerID" />
<input class="form-control" type="text" placeholder="CompanyName" ng-model="new.c.CompanyName" />
<button type="button" class="btn btn-primary" ng-click="AddCustomer()">Save</button>
你的模特看起来很漂亮
new = {
c : {
CustomerID : '',
CompanyName : ''
}
}
这不符合您的客户类别。您应该参考
new.CustomerID
和new.CompanyName
。此外,我将避免使用new关键字作为变量名。如下更新您的HTML:
将new.c.CustomerID
更改为new.CustomerID
<input class="form-control" type="text" placeholder="CustomerID" ng-model="new.CustomerID" />
<input class="form-control" type="text" placeholder="CompanyName" ng-model="new.CompanyName" />
首先要注意javascript对象中的驼峰情况
$scope.new={
customerID:“”,
公司名称:“”
};
$scope.AddCustomer=函数(){
$http.post('/Customer/SaveCustomer',$scope.new).success(function(){});
拯救
试试new.CustomerID和new.CompanyName…@ssilas777谢谢…这很有效…我想知道为什么我正在学习的教程将其标记为new.c.customeridAh,似乎@ssilas777比我强!@Anonymous,很高兴它有效,我已将其作为答案发布。如果有帮助,请标记为正确的anwser。在Angle上使用与您的域相同的命名约定o对象。customer.CustomerID
并发布$scope.customer
<input class="form-control" type="text" placeholder="CustomerID" ng-model="new.CustomerID" />
<input class="form-control" type="text" placeholder="CompanyName" ng-model="new.CompanyName" />
$http.post('/Customer/SaveCustomer', $scope.new).success(function () {
});