如果您无法在 Asp.net Core 中使用搜索功能,可能是由于缺少包或配置问题引起的。以下是一些可能有用的步骤:
确保您已在项目中安装了 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 包。在 Nuget 管理器控制台中运行以下命令:Install-Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
在 Startup.cs 文件中,添加以下代码以启用运行时编译:
services.AddControllersWithViews().AddRazorRuntimeCompilation();
var results = await _context.Entities.Where(e => e.Name.Contains(searchString)).ToListAsync();
通过执行以下步骤,您应该能够让 Asp.net Core 中的搜索功能正常工作。