【发布时间】:2020-08-31 14:27:20
【问题描述】:
这是我的 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开头的国家!非常感谢!
【问题讨论】:
-
使用当前的解决方案,选择应该向下滚动到第一个以“G”开头的条目,并在焦点上并按“G”。你会 som javascript 来更进一步。
标签: javascript c# linq model-view-controller