我的 .cshtml 中有这个
@Html.DropDownListFor(m => m.Attendance.Time02InId, new SelectList(Model.ClockingLocations, "Id", "Name"), new {@class = "form-control select2-allow-clear"})
Model.ClockingLocations
= 列表Clock
public class Clock
{
public int Id { get; set; }
public string Name { get; set; }
}
这是我准备好的文档的jquery
var placeholder = "Select...";
$(".select2-allow-clear").prepend("<option></option>");
$(".select2-allow-clear").select2({
allowClear: true,
placeholder: placeholder,
width: null
});
但是,我的选择列表仍然显示我的第一项Model.ClockingLocations
whenm.Attendance.Time02InId
没有价值,而不是我的占位符。