在ASP.NET CORE API中搜索

问题描述 投票:-1回答:1

你能帮我吗?

我已经在ASP.NET CORE API中进行了项目设计,其中是考试数据库。我需要按班级过滤它。例如:我有整个学校的考试清单,并且我只想为一个班级考试显示JSON。

我编写的代码来自:Microsoft Docs(https://docs.microsoft.com/cs-cz/aspnet/core/web-api/advanced/formatting?view=aspnetcore-3.1),但我的Visual Studio无法识别“ GetByNameSubstring”。我能做什么?

//GET: api/authors/search?namelike=th
    [HttpGet("Search")]
    public IActionResult Search(string namelike)
    {
        var result = _context.GetByNameSubstring(namelike);
        if (!result.Any())
        {
            return NotFound(namelike);
        }
        return Ok(result);
    } 

my code in VS2019

c# asp.net asp.net-core asp.net-apicontroller
1个回答
0
投票
实现在sample code中:

public List<Author> GetByNameSubstring(string nameSubstring) { return List() .Where(a => a.Name.IndexOf(nameSubstring, 0, StringComparison.CurrentCultureIgnoreCase) != -1) .ToList(); }

© www.soinside.com 2019 - 2024. All rights reserved.