I am trying to pass an array of services to my controller. I've tried a bunch of different ways to get it work, serializing the data before going to controller, serializing each service, only thing that seems to work is changing the controller parameter to string and serializing array, then using JsonConvert, but I'd rather not do that.
With the specified code, I am getting the correct number of items in the List, but they all contain a service id with an empty guild, and service provider id is null.
Any ideas?
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;} }