[英]How to filter @Html.DropDownListFor by letter entered in Razor Page?
這是我的 Controller.cs 中的功能
public IActionResult Create()
{
//Create Nation List
var region = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(x => new RegionInfo(x.LCID));
Regex regex = new Regex(@"^[A-Z]+$");
List<Tuple<string, string>> countryList = (from x in region
select new Tuple<string, string>(x.ThreeLetterISORegionName, x.DisplayName))
.Distinct()
.OrderBy(x => x.Item2)
.Where(x => regex.IsMatch(x.Item1))
.ToList<Tuple<string, string>>();
List<string> xxxCountryList = countryList
.Select(x => new string(x.Item2 + " (" + x.Item1 + ")")).ToList();
ViewBag.CountryTupleList = xxxCountryList;
return View();
}
這是我認為的代碼。
<div class="form-group col-lg-8 col-md-8 col-xs-12">
<div class="ml-1">
@{
@Html.DropDownListFor(m => m.Nationality, new SelectList(ViewBag.CountryTupleList), "- Please Select -", new { @class = "form-control" })
}
</div>
</div>
當前,國家/地區顯示在下拉列表中。 一直向下滾動有點乏味。 誰能建議我如何過濾計數器? 即輸入字母“G”,只會顯示以字母 G 開頭的國家! 非常感謝提前!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.