Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过Razor页面中输入的字母过滤@Html.DropDownListFor?_Javascript_C#_Linq_Model View Controller - Fatal编程技术网

Javascript 如何通过Razor页面中输入的字母过滤@Html.DropDownListFor?

Javascript 如何通过Razor页面中输入的字母过滤@Html.DropDownListFor?,javascript,c#,linq,model-view-controller,Javascript,C#,Linq,Model View Controller,这是我的Controller.cs中的函数 public IActionResult Create() { //Create Nation List var region = CultureInfo.GetCultures(CultureTypes.SpecificCultures) .Select(x => new RegionInfo(x.LCID)); Regex rege

这是我的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();
    }
public IActionResult Create()
{
//创建国家列表
var region=CultureInfo.GetCultures(cultureType.SpecificCultures)
。选择(x=>newregioninfo(x.LCID));
正则表达式正则表达式=新正则表达式(@“^[A-Z]+$”;
List countryList=(从区域中的x开始)
选择新元组(x.ThreeLetterISORegionName,x.DisplayName))
.Distinct()
.OrderBy(x=>x.Item2)
.Where(x=>regex.IsMatch(x.Item1))
.ToList();
列表xxxCountryList=国家列表
.Select(x=>newstring(x.Item2+“(“+x.Item1+”))).ToList();
ViewBag.CountryTupleList=xxxCountryList;
返回视图();
}
在我看来,这就是代码

        <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>

@{                                
@Html.DropDownListFor(m=>m.national,新建选择列表(ViewBag.CountryTupleList),“-请选择-”,新建{@class=“form control”})
}

当前,国家/地区显示在下拉列表中。一直向下滚动有点乏味。有人能建议我怎样过滤柜台吗?i、 e.输入字母“G”,仅显示以字母G开头的国家/地区!万分感谢

我相信您正在寻找选择的作为您的解决方案

它支持单选和多选:-)


在当前解决方案中,选择应向下滚动至聚焦时以“G”开头的第一个条目,然后按“G”。您将使用som javascript来进一步了解它。