简体   繁体   English

Angular JS不向Web Api发送数据

[英]Angular JS Not Sending Data To Web Api

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Angular Post method not sending data to web api Controller. Angular Post方法未将数据发送到Web api控制器。 $http call to web api but its null. $ http调用Web api,但它为null。

Define(Initialize) $FirstName , LastName , Email , Number as null first. 首先定义(Initialize) $FirstNameLastNameEmailNumber为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM