note: remember only selected options are posted back on a form post, so if using a form post rather than ajax, you will need to select all options on submit.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
@Html.ListBoxFor generates <ul><li>...</li></ul> and <select> not only <select>
Have you solved this problem?
As far as I know, the @Html.ListBoxFor will generate a <select> html elements, the output as below:
You could use F12 developer tools to check the html elements.
Have you ever override the Html.ListBoxFor method, or whether you are using some JQuery plugins?
If the ListBox items was changed to ul and li, you could use F12 developer tools to check whether the items contain some attribute (which is used to check whether this item is selected or not), might be you could get the selected item via this attribute.
If still have any further question, can you share the related code, so that we could test it on our side. it might be easier for us to help you solve the problem.
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
3 Posts
How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 09, 2018 09:52 AM|vovkor|LINK
Hello everyone!
Help please: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor ? using JavaScript.
All-Star
57864 Points
15491 Posts
Re: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 09, 2018 07:08 PM|bruce (sqlwork.com)|LINK
simple:
note: remember only selected options are posted back on a form post, so if using a form post rather than ajax, you will need to select all options on submit.
Contributor
3710 Points
1431 Posts
Re: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 10, 2018 02:48 AM|Yuki Tao|LINK
Hi vovkor,
According to your requirement,I think you could use the jQuery multiselect Plugin,
you could refer its demo and download its libraries in this link,
For example:
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
161 Points
59 Posts
Re: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 10, 2018 09:41 AM|SharadTripathi|LINK
Hi Vovkor,
If you want to select the same values in first and second list box without removing options from first list box, below sample code may help you.
None
0 Points
3 Posts
Re: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 21, 2018 06:05 PM|vovkor|LINK
Hello bruce. I think it doesn't work for helper @Html.ListBoxFor
All-Star
57864 Points
15491 Posts
Re: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 21, 2018 07:25 PM|bruce (sqlwork.com)|LINK
ListBoxFor just generates a <select multiple>. just be sure you got the id's correct.
None
0 Points
3 Posts
Re: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 23, 2018 03:58 PM|vovkor|LINK
@Html.ListBoxFor generates <ul><li>...</li></ul> and <select> not only <select>
I can select options in sel2 which are selected in sel1
$("#sel1 option:selected").each(function () {
$('#sel2').find('option[value="' + this.value + '"]').prop("selected", true);
});
I see it in console
$("#sel2 option:selected").each(function () {
console.log(' Selected ');
console.log(this.text + ' -> ' + this.value);
});
but it is not enough. Rows are not selected in dropDownList.
All-Star
45489 Points
7008 Posts
Microsoft
Re: How to copy selected values from one Html.ListBoxFor to other Html.ListBoxFor
Dec 28, 2018 06:21 AM|Zhi Lv - MSFT|LINK
Hi vovkor,
Have you solved this problem?
As far as I know, the @Html.ListBoxFor will generate a <select> html elements, the output as below:
You could use F12 developer tools to check the html elements.
Have you ever override the Html.ListBoxFor method, or whether you are using some JQuery plugins?
If the ListBox items was changed to ul and li, you could use F12 developer tools to check whether the items contain some attribute (which is used to check whether this item is selected or not), might be you could get the selected item via this attribute.
If still have any further question, can you share the related code, so that we could test it on our side. it might be easier for us to help you solve the problem.
Best regards,
Dillion