问题
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