ASP.NET MVC 中的 MultiSelectList 有问题吗?
Problem with MultiSelectList in ASP.NET MVC?
这段代码有什么问题?我不知道为什么我不能 select 此下拉列表(如下所示)中的多个值?
<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>
改用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"})
这段代码有什么问题?我不知道为什么我不能 select 此下拉列表(如下所示)中的多个值?
<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>
改用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"})