【发布时间】:2016-10-28 23:52:47
【问题描述】:
【问题讨论】:
-
使用 ng-model insted of data-ng-model,让我知道
-
是的,我认为 Rakeschand 是对的,你需要初始化,让我来投票
标签: angularjs web asp.net-web-api
【问题讨论】:
标签: angularjs web asp.net-web-api
先定义(初始化)$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
};
并将ng-model作为user.FirstName传入
编辑:
在CreateUser 函数之外构建$scope.user
$scope.CreatUser=function(){
$http{(...)};
}
结束
【讨论】:
$scope.user,它在 CreateUser 方法内重新启动
将 $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
【讨论】: