I have two Selects Multiple where their function is to change values as in the image below:
ThefirstoneintherealisaDropDownListwherehelooksforthebankinformation,followshiscode:
@Html.DropDownList("Avaible", ViewBag.Account as SelectList, new { multiple = "multiple", id = "Avaliable", name = "Avaliable" })
The other is a Select that receives these values, it follows your code:
<select style="width:70px" id="Included" name="Included" multiple></select>
The two buttons transition the data from one to the other via JavaScript:
function Incluir() {
$("#Included").append($("#Avaliable option:selected"));
}
And then it populates the select that gets the values, the problem is, I need to get those values and store them in a ViewModel variable called Accounts
public List<int> Accounts { get; set; }
I have tried to do a JavaScript method that returns all values of Select, but I can not store this in the Accounts variable, this is the function I did:
function displayResult() {
var x = document.getElementById("Included");
var array = [];
var i;
for (i = 0; i < x.length; i++) {
array[i] = x.options[i].value;
}
alert(array);
$('#Accounts').push(array);
}
But he can not popular Accounts, could anyone help me how popular this List Accounts with the Select values? If you have a better method or help to transfer the Array to the Accounts. Ah forgot to speak, in the View has a field referencing the Accounts:
@Html.HiddenFor(m => Model.Accounts)