I can't seem to get the json (verified valid) to the UpdateCaps controller from ListBox:
Controller:
public IActionResult UpdateCaps(List<SelectListItem> selectedItems)
{
var test = selectedItems;
return Json(test);
}
ListBox:
@(Html.Kendo().ListBox()
.Name("selected")
.ConnectWith("optional")
.Selectable(ListBoxSelectable.Multiple)
.DropSources("optional")
.DataTextField("Description")
.DataValueField("Id")
.Toolbar(toolbar =>
{
toolbar.Position(ListBoxToolbarPosition.Right);
})
.DataSource(source => source
.Custom()
.Type("aspnetmvc-ajax")
.Transport(transport => transport
.Read(read => read.Action("GetSelectedCapsUnits", "OrgStructure").Data("level1Select"))
)
)
.Events(events => events
.Add("onAdd")
.Remove("onRemove")
)
.BindTo(new List<SelectListItem>())
)
The onAdd in the listbox triggers this javascript:
function onAdd(e) {
console.log(e.dataItems);
console.log(JSON.stringify({ selectedItems: e.dataItems }))
$.ajax({
type: "POST",
url: "/OrgStructure/UpdateCaps",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ selectedItems: e.dataItems }),
dataType: "json",
success: function (result) {
alert("Successfully sent to server: " + result.map(function (x) {
return x.Text
}))
}
});
$('#selectedListBox').text(' ' + e.dataItems.length + " added - saved");
}
Verified the JSON string is valid:
With: console.log(JSON.stringify({ selectedItems: e.dataItems }))

JSON.stringify(...). Essentially try sending the object, rather than a string representation of the object.data: e.dataItems,but stillCount = 0