Click here to Skip to main content
15,887,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi in my mvc project have multiselect dropdownlist when i used it in edit mode
and selected some item , only pass old value


please help

What I have tried:

this my dropdownlist
>
@Html.DropDownListFor(model => model.SelectedUnitOfCompanyFID, ViewBag.unit as List<SelectListItem>, new { @class = "example-multiple-selected", id = "unit-multisel", multiple = "multiple" })



and javascript code for pass all selected item

JavaScript
<pre>   <script type="text/javascript">


        $(document).ready(function () {

            $("#unit-multisel").change(function () {




            
                var SelectedVal = $('#unit-multisel').val();

                var jsonval = JSON.stringify(SelectedVal);
             


                $("#rdbgroup-multisel").html('');
              
                if (SelectedVal != '') {

                    $.get('/Account/getgrouplist/',

                        {


                            "orgFId": jsonval
                        }).success(function (data) {


                            $.each(data, function (index, item) {
                                $("#rdbgroup-multisel").append($("<option></option>").attr("value", item.uf)
                                    .text(item.description));



                            });


                            $('select#rdbgroup-multisel').multiselect('rebuild');


                        });
                }
            });
        })

    </script>
Posted
Comments
MadMyche 31-Mar-20 12:56pm    
Use the Browser's debugger first to see if there are errors; javascript really does not like hyphens in attribute names
mohamad_ali 31-Mar-20 15:02pm    
Thnx for your answer but its work in create mode ,only it dosent work in edit mode
Richard Deeming 1-Apr-20 11:21am    
A drop-down list doesn't support multiple selected items. Which plugin are you using?

You're also going to need to change your model to support multiple selection. At the moment, it looks like you have a single property to represent the single selected item, which obviously won't work.

Step-By-Step Implementation of MultiSelectList In .NET MVC[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900