So, first of all I best explain that I am calling this method via AngularJS. I have many other controllers, but what makes this one unique is that the model only has one property:
public class Subscriber
{
public string Email { get; set; }
}
And so my controller method (which is very simple) just looks like this:
[HttpPost]
[Route("")]
public async Task<IHttpActionResult> Create(Subscriber model)
{
// Try to find the subscriber
var subscriber = await this.service.GetAsync(model.Email);
// If the subscriber does not exist
if (subscriber != null) {
// Create the subscriber
this.service.Create(model);
// Save the datbase changes
await this.unitOfWork.SaveChangesAsync();
}
return Ok();
}
I didn't create a RequestModel although I might just do that to stop my method being invoked when the model is null.
So, the issue is just that, the model is always null. I have my AngularJS service which looks like this:
.service('SubscriberService', ['Api', function (api) {
var apiUrl = 'api/subscribers';
// Subscribe
this.subscribe = function (email) {
// Create our model
var model = {
email: email
};
console.log(model);
// Create our subscriber
return $http.post(apiUrl, model);
};
}])
in that, the console log shows the model with the email value. In my web config I have this line:
serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
which handles the camel case, although I have also tried with Pascal case to no avail.
Does anyone know why it isn't working? I have spent too much time staring at it.