dfmmalaw
5/15/2017 - 4:56 PM

Creating a Web API called from AJAX POST request that passes multiple values in object

Creating a Web API called from AJAX POST request that passes multiple values in object

self.removeViews = function () {

            var data = {
                selectedViewsForClient: self.selectedViewsAssignedToCandidateForClientUser().toString(),
                volPoolIds: populateSelectedVolPoolIds().toString()
            };

            var jsonData = ko.toJSON(data);

            $.ajax({
                url: "../../japi-act/ClientView/removeViews",
                type: "POST",
                async: false,
                contentType: "application/json; charset=utf-8",
                cache: false,
                data: jsonData,
                success: location.reload(),
                error: handleEditViewsErrors
            });
        };        
[System.Web.Http.HttpPost]
[ClientUserApi]
public ActionResult removeViews(ClientViewModel model)
{
    List<long> clientViewIdList = parseStringToIds(model.selectedViewsForClient);
    List<long> volPoolIdList = parseStringToIds(model.volPoolIds);

    long clientId = webRequestState.ClientUser.ClientId;

    clientViewService.removeViews(clientViewIdList, volPoolIdList, clientId);

    return null;
}