经典 asp .net core 中的组合框有其他选择吗?
我认为你可以使用 Select2.js:
<div class="col-md-10">
<label> Account Number</label>
<div class="input-group">
<select id="mySelect2" class="form-control accountSelect">
<option value="Select" disabled>Select</option>
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
<option value="ddd">ddd</option>
</select>
</div>
</div>
@section Scripts
{
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script>
$(document).ready(function () {
$("#mySelect2").select2();
})
</script>
}
结果:
如果您的选择列表资源来自后端,您可以更改视图,如下所示:
索引.cshtml:
@model TestVM
<div class="col-md-10">
<label> Account Number</label>
<div class="input-group">
<select id="mySelect2" asp-items="Model.Select" class="form-control"></select>
</div>
</div>
型号:
public class TestVM
{
public IEnumerable<SelectListItem> Select{ get; set; }
}
控制器:
[HttpGet]
public async Task<IActionResult> Index()
{
var model = new TestVM()
{
Select= new List<SelectListItem>() {
new SelectListItem() { Value = "1", Text = "aaa" },
new SelectListItem() { Value = "2", Text = "bbb" },
new SelectListItem() { Value = "3", Text = "ccc" },
new SelectListItem() { Value = "4", Text = "ddd" }
}
};
return View(model);
}