【问题标题】:How to filter @Html.DropDownListFor by letter entered in Razor Page?如何通过在 Razor 页面中输入的字母过滤 @Html.DropDownListFor?
【发布时间】: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


【解决方案1】:

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

https://julesjanssen.github.io/chosen/

它支持单选和多选:-)

亲切的问候

【讨论】:

    猜你喜欢
    • 2021-12-03
    • 2013-04-24
    • 2019-05-01
    • 2019-04-09
    • 2014-01-07
    • 2021-03-30
    • 2021-01-24
    • 2021-02-16
    • 2020-11-06
    相关资源
    最近更新 更多