[英]Angular JS Not Sending Data To Web Api
首先定义(Initialize) $FirstName
, LastName
, Email
, Number
为null。
$scope.FirstName = null;
$scope.LastName = null;
$scope.Email = null;
$scope.Number = null;
或者您可以只使用$scope.user
作为
$scope.user = {
id : 0,
FirstName : null,
LastName : null,
Email : null,
Password : null
};
并以user.FirstName
传入ng-model
编辑:
在CreateUser
函数之外构建$scope.user
$scope.CreatUser=function(){
$http{(...)};
}
完
将$ scope.User移至控制器作用域:
app.controller('myCtrl',function($scope,$http){
$scope.User = {
id : 0,
FirstName : null,
LastName : null,
Email : null,
Password : null
};
$scope.CreatUser=function(){
$http{(...)};
}
})
并将ng-model作为User.FirstName传递。
protected void Application_BeginRequest() {
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS"){
Response.Flush();
}
}
您正面临此问题,因为您的标头请求content-type
为: application/x-www-form-urlencoded
,将无法正常工作。 尝试将其更改为application/json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.