Angular Post method not sending data to web api Controller. $http call to web api but its null.
-
use ng-model insted of data-ng-model at all, let me knowJigar7521– Jigar75212016-10-27 10:41:53 +00:00Commented Oct 27, 2016 at 10:41
-
Yes i think Rakeschand is right, you need to initialize, let me to upvoteJigar7521– Jigar75212016-10-27 10:43:14 +00:00Commented Oct 27, 2016 at 10:43
Add a comment
|
4 Answers
Define(Initialize) $FirstName, LastName, Email, Number as null first.
$scope.FirstName = null;
$scope.LastName = null;
$scope.Email = null;
$scope.Number = null;
or You could just use $scope.user as
$scope.user = {
id : 0,
FirstName : null,
LastName : null,
Email : null,
Password : null
};
And pass in ng-model as user.FirstName
EDIT:
Build $scope.user outside the CreateUser Function
$scope.CreatUser=function(){
$http{(...)};
}
ENDS
4 Comments
user2951849
$scope.FirstName = null; $scope.LastName = null; $scope.Email = null; $scope.Number = null; $scope.User = { Id:'0', FirstName: '', LastName: '', EMail: '', Password: '', Mobile:'0' };
user2951849
$scope.CreateUser = function () { debugger; $http({ method: 'POST', dataType:'json', url: 'localhost:50048/api/SingUp/Post', data: $scope.User, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }).then(function successCallback(response) { $scope.productsData.push(response.data); $scope.clear(); alert("Successfully !!!"); }, function errorCallback(response) { }); };
user2951849
I've change my code but still its pass null , i've also remove data and now i just use ng-model.
Rakesh Chand
Build
$scope.user outside CreateUser function, it's re initiating inside the CreateUser methodMove $scope.User to the controller scope :
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.
5 Comments
Bayan Abuawad
depanding on this that you have send to me ,i.sstatic.net/1gjyS.png , youre not doing it right . you need to delete the $scope.user that inside the CreatUser function
user2951849
if m not sending model and m sending sting value but still its sending null. can you please check header and content-type value is ok?
Bayan Abuawad
i will edit my answer above with the full code , give me a sec
Bayan Abuawad
public httpResponsMessage Post([FromBody] SignUpView DataFromUI){
user2951849
i've also try with Post([FromBody] SignUpView DataFromUI) but its not working.


