1

I am using ‘choosen-select’ for multiselect or single select dropdown list.

Depends on condition dropdown change from single select to multiselect.

@Html.DropDownListFor(m => m.SelectedPlants, new MultiSelectList(Model.PlantList, "Value", "Text", Model.PreSelectedPlants.Select(a => a.Value))
                        , new { @class = "chosen-select", ID = "ddlplants", Style = "width:100%", data_placeholder = "Choose Plants..", multiple = "multiple" })

I am trying to remove ‘multiple’ from dropdownlist attribute using jquery but it’s not working.

Please any one helps me.

Thanks.

daredevil
  • 127
  • 2
  • 15
  • 1
    Is there any reason you cannot remove it from the Razor code you've posted in the question ..? If you want to do it in jQuery use `attr()`, but note that you'll need to destroy and re-initialise the chosen library you've instantiated on the select for the change to be picked up – Rory McCrossan Nov 21 '17 at 11:56
  • Why are you adding `multiple = "multiple"` if your do not want it to be multiple? –  Nov 21 '17 at 11:57
  • @StephenMuecke I want single select and multiselect in one dropdown depends on condition.Dropdown change from single to multiple and viceversa. – daredevil Nov 21 '17 at 12:04
  • That makes no sense - there are multiple errors in your code. First a `` binds to an array (say `IEnumerable` so your would need 2 separate properties. Second To create a ` –  Nov 21 '17 at 12:08
  • 1
    Third using `new MultiSelectList()` with `PlantList` which appears to already be `IEnumerable` is just pointless extra overhead - it generates another identical `IEnumerable`. Forth, the last parameter in your `new MultiSelectList()` is also pointless because its ignored. Its the value of `SelectedPlants` that determines what is selected –  Nov 21 '17 at 12:11

0 Answers0