I need to pass a list of ids, a username, and id to my web api as a post. The list of ids I'm retrieving from a knockout array, id is the selected id from a radio button list (populated from a knockout array) and username is from a public variable. I tried passing it like this:
self.editDocuments = function (userName, Id, listOfIds) {
return $.ajax({
type: "post",
url: "DocumentsAPI/EditDocuments",
data: { 'listOfIds': listOfIds, 'Id': Id, 'userName': userName },
contentType: "application/json"
});
}
My web api is as follows:
public string EditDocuments([FromBody] string listOfIds, int Id, string userName)
{
return listOfIds;
}
I'm getting a 500 internal server error. If I run in fiddler it runs but the parameters are null. If I send only one parameter it also runs but the parameter is null.
Based on this post it seems like I should be passing an object. Does that mean I need to create an object on the server and client side? It seems to me a bit like double work creating an object from different existing objects.