Hello,
I am trying to post form data to an ASP.NET Web API with angular. So I have:
<form name="form" data-ng-controller="SubscriberController"><input data-ng-model="subscriber.name" name="name" type="text"/><input data-ng-model="subscriber.email" name="email" type="text"/><input data-ng-click="create(subscriber)" type="submit" value="Send" /></form> application.service('SubscriberService', function ($http) { return { Create: function (subscriber) { console.log(subscriber); return $http.post('api/subscribers/create', { 'subscriber': subscriber }); } } }); application.controller('SubscriberController', function SubscriberController($scope, SubscriberService) {$scope.create = function (subscriber) { SubscriberService.Create(subscriber) .success(function (data, status, headers, config) { }) .error(function (data, status, headers, config) { }); }; });
Finally on the ASP.NET API I have the following:
public class SubscriberController : ApiController { [Route("api/subscribers/create"), HttpPost] public void Create([FromBody]SubscriberCreateModel subscriber) { // Create subscriber } // Create } public class SubscriberCreateModel { public Int32 Country { get; set; } public String Email { get; set; } public String Name { get; set; } }
On my angular service I am logging the subscriber and I get:
Object { name="john", email="john@something.pt" }
The problem is that on the controller both subscriber properties, email and name, are null ...
Any idea what I am missing?