Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 将对象从AngularJS传递到ASP.NET MVC控制器_Asp.net Mvc_Angularjs - Fatal编程技术网

Asp.net mvc 将对象从AngularJS传递到ASP.NET MVC控制器

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

我试图从AngularJS向我的MVC控制器传递一些数据,但是MVC控制器上的Customer对象总是空的。我错过了什么

棱角分明

        $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 () {

        });