I have a simple test to try to understand $ http.post from AngularJS to ASP.NET WebAPI. The post succeeds, but the resulting value in the API looks like null. I checked this and saw that the $ scope object is relevant before submitting.
I checked all the places and I see that ASP.NET WebAPI processes message data in strange ways.
Here is my HTML for input input, Basic.html:
<form name="basicItem" novalidate ng-app="app" ng-controller="ItemCtrl">
<label id="titlelabel" class="required">Title</label>
<input ng-model="item.Title" type="text" id="titlefield" name="Title"
required />
This is the code from ItemController.js that checks validation and messages (I use CORS since both of these programs have separate domains):
app.controller("ItemCtrl", ['$scope', '$http', function ($scope, $http) {
$scope.submitForm = function (form) {
if (form.$valid) {
item = {
"Title": $scope.item.Title,
}
alert($scope.item.Title);
$http.post("http://localhost:50261",
{
testTitle: $scope.item.Title
}).success(function (result) {
alert('Success!');
}).error(function (data) {
alert("Valid but didn't connect");
console.log(data);
})
And this is the code in the API controller, EntryController.cs:
[HttpPost]
public string CreateEntry([FromBody]string testTitle)
{
return testTitle;
}
[FromBody] . , , "=", , , . .