0

I have 2 lists in my Viewmodel:

...
public List<District> SelectedDistricts { get; set; }
public List<District> DistrictSelected { get; set; }
...

(The SelectedDistricts and the DistrictSelected are equal.)

and I'd like this:

@Html.DropDownListFor(m => m.SelectedDistricts, new MultiSelectList(Model.SelectedDistricts, "uId", "cName"), new { multiple = "multiple", @class = "form-control" })
@Html.DropDownListFor(m => m.DistrictSelected, new MultiSelectList(Model.SelectedDistricts, "uId", "cName", Model.SelectedDistricts.Select(y => y.uID).ToArray()), new { multiple = "multiple", style = "display:none;" })

My problem the options of the second listbox are not selected on the page.

Sándor Hatvani
  • 435
  • 1
  • 7
  • 21
  • In you second list box remove the "style =display : none;" – Karthick Rajan Jun 13 '17 at 09:57
  • Apart from the selection issue, your code will not bind to anything anyway. you cannot bind a `` posts back a single value and a ` –  Jun 13 '17 at 10:00
  • Also refer [Can the ViewBag name be the same as the Model property name in a DropDownList?](http://stackoverflow.com/questions/37161202/will-there-be-any-conflict-if-i-specify-the-viewbag-name-to-be-equal-to-the-mode/37162557#37162557) –  Jun 13 '17 at 10:01
  • Stephen Muecke, you are right, tanks. The model name is DistrictSelected and the MultiSelectlist's name SelectedDistrict so it isn't problem with names, I think. Karthick Rajan, your solution does not work because I rename the secons list e.g. "something" the selection works. – Sándor Hatvani Jun 13 '17 at 10:27

0 Answers0