我使用ASP核心剃刀页。 这是我的Edit.cshtml.cs:
[BindProperty]
public List<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> CCusers { get; set; }
and here I fill CCusers with data:
CCusers =new List<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>() {
new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem() { Value = "1", Text = "HR", Selected = true },
new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem() { Value = "2", Text = "IT", Selected = false },
new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem() { Value = "3", Text = "Account", Selected = false },
};
在剃刀页,我用了两个不同的选择:
<select asp-for="CCusers" asp-items="@Model.CCusers" id="CCusers" multiple="multiple" class="selectpicker"> </select>
//and this:
@Html.DropDownList("NewSelect", Model.CCusers, new { @class = "selectpicker", @multiple = "multiple" })
而这两者的结果:
<select id="CCusers" multiple="multiple" class="selectpicker" name="CCusers">
<option value="1">HR</option>
<option value="2">IT</option>
<option value="3">Account</option>
</select>
<select class="selectpicker" id="NewSelect" multiple="multiple" name="NewSelect">
<option selected="selected" value="1">HR</option>
<option value="2">IT</option>
<option value="3">Account</option>
</select>
而@ Httml.DropDownList做了它的核心选择没有设置选定的项目。 我很想念在第一选择?