[英]Angular JS Not Sending Data To Web Api
Define(Initialize) $FirstName
, LastName
, Email
, Number
as null first. 首先定义(Initialize)
$FirstName
, LastName
, Email
, Number
为null。
$scope.FirstName = null;
$scope.LastName = null;
$scope.Email = null;
$scope.Number = null;
or You could just use $scope.user
as 或者您可以只使用
$scope.user
作为
$scope.user = {
id : 0,
FirstName : null,
LastName : null,
Email : null,
Password : null
};
And pass in ng-model as user.FirstName
并以
user.FirstName
传入ng-model
EDIT: 编辑:
Build $scope.user
outside the CreateUser
Function 在
CreateUser
函数之外构建$scope.user
$scope.CreatUser=function(){
$http{(...)};
}
ENDS 完
Move $scope.User to the controller scope : 将$ scope.User移至控制器作用域:
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. 并将ng-model作为User.FirstName传递。
protected void Application_BeginRequest() {
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS"){
Response.Flush();
}
}
you are facing this issue because your header request content-type
is : application/x-www-form-urlencoded
which will not work correctly. 您正面临此问题,因为您的标头请求
content-type
为: application/x-www-form-urlencoded
,将无法正常工作。 Try change it to application/json
尝试将其更改为
application/json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.