1
Guys I own two Selects Multiple where their function is to change values as shown in the image below:
The first in real is a Dropdownlist where he searches the bank’s information, follows its code:
@Html.DropDownList("Avaible", ViewBag.Account as SelectList, new { multiple = "multiple", id = "Avaliable", name = "Avaliable" })
The other is one Select that receives these values, follows its code:
<select style="width:70px" id="Included" name="Included" multiple></select>
The two buttons transition data from one to the other via Javascript:
function Incluir() {
$("#Included").append($("#Avaliable option:selected"));
}
And then it populates the select that receives the values, the problem is, need to take these values and store in a variable of Viewmodel Call Accounts
public List<int> Accounts { get; set; }
I tried to do Javascript method that returns all Select values, but I can’t store it 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’t get Accounts popular, could anyone help me how popular this Accounts List with Select values ? If you have a better method or help to transfer the Array to Accounts. Ah forgot to mention, the View has a field referencing the Accounts:
@Html.HiddenFor(m => Model.Accounts)
So, the problem is that when it comes to taking this List and playing for Controller popular Accounts (which is in viewModel), it does not send the values
– Dan Oliveira
An alternative is you rename select "Included" to "Accounts" and before Submit select all its options.
– Leandro Angelo
Dude It worked, thanks @Leandroangelo !!
– Dan Oliveira
just don’t forget to select all items before Submit, if the user deselects they won’t arrive for you in the controller
– Leandro Angelo