[英]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.