Angular JS Not Sending Data To Web Api

谁说我不能喝 提交于 2020-01-24 21:08:55

问题


Angular Post method not sending data to web api Controller. $http call to web api but its null.


回答1:


Define(Initialize) $FirstName, LastName, Email, Number as null first.

$scope.FirstName = null;
$scope.LastName = null;
$scope.Email = null;
$scope.Number = null;

or You could just use $scope.user as

$scope.user = {
    id : 0,
    FirstName : null,
    LastName : null,
    Email : null,
    Password : null
};

And pass in ng-model as user.FirstName

EDIT:

Build $scope.user outside the CreateUser Function

$scope.CreatUser=function(){
   $http{(...)};
}

ENDS




回答2:


Move $scope.User to the controller scope :

app.controller('myCtrl',function($scope,$http){
   $scope.User = {
    id : 0,
    FirstName : null,
    LastName : null,
    Email : null,
    Password : null
    };

    $scope.CreatUser=function(){
      $http{(...)};
    }

})

And pass in ng-model as User.FirstName.




回答3:


protected void Application_BeginRequest() {
  if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS"){
    Response.Flush();
  }
}



回答4:


you are facing this issue because your header request content-type is : application/x-www-form-urlencoded which will not work correctly. Try change it to application/json



来源:https://stackoverflow.com/questions/40282466/angular-js-not-sending-data-to-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!