Using the below code, I am able to pass this content to my webapi which receives it like
public void Post(Business.Entities.api.newsalert alert)
{
//do stuff here
}
category = $('#dt_category').val();
title = $('#inputTitle').val();
url = $('#inputURL').val();
comments = $('#inputComments').val();
subject = "News Alert / Alerte Nouvelles: " + title;
var dataJSON = {
userid: username,
to: "[email protected]",
url: url,
subject: subject,
title: title,
source: "My company",
comments: comments,
category: category
};
$.ajax({
type: 'POST',
url: "http://mywebserver/api/NewsAlerts",
data: JSON.stringify(dataJSON),
contentType: 'application/json; charset=utf-8',
success: function (data) {
q.resolve();
}
});
However, my boss has asked me to make the Categories select use multiple..
Therefore I did this
category = $('#dt_category').val(); //apples, oranges, peaches
title = $('#inputTitle').val();
url = $('#inputURL').val();
comments = $('#inputComments').val();
subject = "News Alert / Alerte Nouvelles: " + title;
var categories = [];
$(category).each(function (index) {
categories.push({ 'category': category[index] });
});
var dataJSON = {
userid: username,
to: "[email protected]",
url: url,
subject: subject,
title: title,
source: "My company",
comments: comments,
category: categories
};
$.ajax({
type: 'POST',
url: "http://mywebserver/api/NewsAlerts",
data: JSON.stringify(dataJSON),
contentType: 'application/json; charset=utf-8',
success: function (data) {
q.resolve();
}
});
But when my webapi receives the ajax Put, it is always null. I'm assuming I need to somehow make the Categories into some kind of a child node but i'm not sure.
Business.Entities.api.newsalertexpecting a list ? meaningBusiness.Entities.api.newsalert.Categoryistypeof List<int>categorydatatype asList<string>