Thanks for your reply.
I tried your sample and works fine,
the JSON.stringify(target1.model.dataSource) return a string like this:
"[{"text":"ASP.NET"},{"text":"C++"},{"text":"dBase"}]"
In my situation return a string like this:
"dataSource":{"url":"/Centri/ListaCentriUtente?userID=bfa07f07-62f7-4f3c-b775-3a27dfc98cab","json":[],"timeTillExpiration":0,"cachingPageSize":0,"jsonp":"callback","dataType":"json","offline":false},"adaptor":{"options":{"from":"table","requestType":"json","sortBy":"sorted","select":"select","skip":"skip","group":"group","take":"take","search":"search","count":"requiresCounts","where":"where","aggregates":"aggregates"},"pvt":{}}}"
I think the difference is that in my listBox I use a datasource with urldataadaptor, in yours use IEnumerable from viewBag.
Do you have a solution?
function onsave(e) {
target1 = $("#ListaCentriDisponibili").data("ejListBox");
target2 = $("#ListaCentriUtente").data("ejListBox");
selections = target1.element.find("li");
var items = [];
for (i = 0; i < selections.length; i++) {
var item = { text: selections[i].innerText, uniqueKey: selections[i].value };
items.push(item); // Gets only the current item in the Listbox
}
$.ajax({
type: 'POST',
dataType: 'json',
url: '@Url.Action("ListBoxpost", "ListBox")',
data: {
listdata1: JSON.stringify(items), listdata2: JSON.stringify(target2.model.dataSource), listdata3: JSON.stringify(target1.getListData()) // Gets all items in Listbox
},
success: function (response) {
alert("Success");
},
error: function (response) {
alert("Success");
}
});
}
|
The solution to find current li element in the element is the right choice for me, and i had thought the same solution before your reply, because i need the all items in the listBox after drag drop not the all items returned from datasource.
I thought there was a ListBox method that do this, but the solution with li tag is ok
The getListData() return all items that returns the action @Url.Action("DataSource", "ListBox") and this is not realy useful.
Thanks
Nicola