0

What's wrong with this code? i don't know exactly why i can't select multiple values from this Dropdownlist (given below)?

<div class="form-group">
    <label>Movie</label>
    @Html.DropDownListFor(m => m.Movies, new MultiSelectList(Model.Movies, "id", "name"), "Select Movie", new { @class = "form-control"})
</div>

Source Code From Google Chrome:

<select class="form-control" id="Movies" name="Movies"><option value="">Select Movie</option>
   <option value="1">Movie 1</option>
   <option value="2">Movie 2</option>
   <option value="3">Movie 3</option>
   <option value="4">Movie 4</option>
   <option value="5">Movie 5</option>
   <option value="8">Movie 6</option>
   <option value="9">Movie 7</option>
</select>
8
  • What does the generated HTML look like? (View-source in the browser). Commented Jan 21, 2019 at 15:59
  • its generates the html as expected but i can't select multiple values from it using Ctrl key. Commented Jan 21, 2019 at 16:02
  • So the HTML has <select multiple> does it? Commented Jan 21, 2019 at 16:03
  • @Neil Look the Question one again please..it added the html source code as well.. Commented Jan 21, 2019 at 16:04
  • 1
    @Neil .. I got it....i have to also specify the multiple attribute to true. Commented Jan 21, 2019 at 16:08

1 Answer 1

1

Use ListBoxFor instead:

@Html.ListBoxFor(m => m.Movies, new SelectList(Model.Movies, "id", "name"), "Select Movie", new { @class = "form-control"})

Or add multiple attribute to the DropDownListFor

@Html.DropDownListFor(m => m.Movies, new MultiSelectList(Model.Movies, "id", "name"), "Select Movie", new {multiple = "true", @class = "form-control"})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.