Let's say I have an array in my client side model:
vm.dataSheets = [
{ value: 0, text: localize.getLocalizedString('_ProductsAndServices_'), selected: selected},
{ value: 1, text: localize.getLocalizedString('_Holidays_'), selected: selected },
{ value: 2, text: localize.getLocalizedString('_Locations_'), selected: selected },
{ value: 3, text: localize.getLocalizedString('_OpHours_'), selected: selected },
{ value: 4, text: localize.getLocalizedString('_Users_'), selected: selected }
];
I bind this to a checkbox list on the HTML. I want to send the values of those which are checked, to the web API. Using angularJS I can filter the selected objects as follows:
$filter('filter')(vm.dataSheets, { selected: true })
This will return an array of the entire object. Is there a short way to just retrieve the selected values as 1,2,3, etc...?
Right now, I send the data to the Web API as follows:
var fd = new FormData();
fd.append('file', file);
fd.append('clientId', $rootScope.appData.clientId);
fd.append('sheets', $filter('filter')(vm.dataSheets, { selected: true }));
$http.post("TIUSP/systemengine/ClientSupply", fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).success(function () {
}
In the web API, how do I retrieve the selected values? When I use
HttpContext.Current.Request["sheets"];
it gives me a string as [object, object][object, object], etc...
JSON.strigify($filter('filter')(vm.dataSheets, { selected: true })), However you have to deserialize on API side