I'm struggling to pass an array of services to my controller. I've experimented with different methods, like serializing the data before sending it to the controller, serializing each service individually, and converting the controller parameter to a string and then serializing the array using JsonConvert. The latter approach seems to work, but I would prefer not to do it this way.
The current code results in the correct number of items in the List, but they all have a service ID with an empty guild and the service provider ID is null.
Any suggestions on how to resolve this issue?
Javascript
function ServiceItem() { this.ServiceProviderID = 'all'; this.ServiceID = ''; } var selecteditems= (function () { var services = new Array(); return { all: function() { return services; }, add: function(service) { services.push(service); } }; })(); var reserved = []; $.each(selecteditems.all(), function(index, item){ reserved.push({ ServiceID: item.ServiceID, ServiceProviderID: item.ServiceProviderID}); }); getData('Controller/GetMethod', { items: reserved }, function(result) { }); var getData = function (actionurl, da, done) { $.ajax({ type: "GET", url: actionurl, data: da, dataType: "json", async: true, success: function (d) { if (typeof (done) == 'function') { var str = JSON.stringify(d); done(JSON.parse(str)); } } }); };
Controller
public JsonResult GetMethod(List<CustomObject> items) { }
Custom Object
public class CustomObject { public Guid ServiceID {get;set;} public Guid? ServiceProviderID {get;set;} }