[英]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.