如何为下拉菜单项创建搜索栏

我的模型如下:

winrt::Windows::Storage::StorageFile nextFile = nullptr;
winrt::microsoft::Graphics::Canvas::Svg::CanvasSvgDocument nextSvg = nullptr;
winrt::Windows::Storage::Streams::IRandomaccessStream  fileStream = nullptr;

nextFile = co_await KnownFolders::Pictureslibrary().GetFileAsync(L"Freesample.svg");
fileStream = co_await nextFile.OpenReadAsync();

SvgImageSource sourcee = SvgImageSource();
co_await sourcee.SetsourceAsync(fileStream);
MyImage().Source(sourcee); 

我当前的搜索功能如下:

public enum NSurname
{
    JohnDoe,PeterSmith
}
public class RaidRequest
{
    public int Id { get; set; }
    public Permissions access { get; set; }
    public Group UserOrAdmin { get; set; }
    public string Department { get; set; }
    public NSurname NameSurname { get; set; }
    public string Reason { get; set; }
    public string UNCPath { get; set; }
}

这就是我的控制器中的外观

<form asp-controller="Raidrequests" asp-action="Index" method="get">
<p>
    Search: <input type="text" name="SearchString">
    <input type="submit" value="Filter" />
</p>

我可以使它与字符串Reason,UNCPath或Department一起使用,但不能与枚举一起使用。 当我尝试使用枚举时会出现此错误:

  

CS1929 C#不包含“包含”的定义,并且最佳扩展方法重载需要类型的接收器

jinwenyu2002 回答:如何为下拉菜单项创建搜索栏

尝试以下解决方案。

public class RaidRequest
{
    public int Id { get; set; }
    public string Access { get; set; }
    public string UserOrAdmin { get; set; }
    public string Department { get; set; }
    public string NameSurname { get; set; }
    public string Reason { get; set; }
    public string UNCPath { get; set; }
}

public async Task<IActionResult> Index(string searchString)
    {

        var requests = from m in _context.RaidRequest select m;

        if (!String.IsNullOrEmpty(searchString))
        {
            requests = requests.Where(s => s.Reason.Contains(searchString) || s.UNCPath.Contains(searchString) || s.Department.Contains(searchString)|| s.Access.Contains(searchString)|| s.NameSurname.Contains(searchString)|| s.UserOrAdmin.Contains(searchString));
        }

        return View(await requests.ToListAsync());
    }
,

解析枚举

requests = requests.Where(s => s.NameSurname ==(NSurname)Enum.Parse(typeof(NSurname),searchString));
本文链接:https://www.f2er.com/3119443.html

大家都在问