此代码有什么问题?我不知道为什么我不能从此Dropdownlist中选择多个值(如下所示)?
<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>
来自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>
答案 0 :(得分:1)
改为使用ListBoxFor
:
@Html.ListBoxFor(m => m.Movies, new SelectList(Model.Movies, "id", "name"), "Select Movie", new { @class = "form-control"})
或将multiple
属性添加到DropDownListFor
@Html.DropDownListFor(m => m.Movies, new MultiSelectList(Model.Movies, "id", "name"), "Select Movie", new {multiple = "true", @class = "form-control"})