由于我正在为ASP.net MVC创建过滤器搜索框,因此我想寻求帮助。我遵循了本教程https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/sort-filter-page?view=aspnetcore-2.2,但是此代码有错误。
public async Task <IActionResult> Index(string searchString)
{
using (DBModelEntities dbModel = new DBModelEntities())
{
ViewData["CurrentFilter"] = searchString;
var products = (from p in dbModel.Products
select p);
if(!String.IsNullOrEmpty(searchString))
{
products.Where(p => p.productName.Contains(searchString));
}
return View(await products.AsNoTracking().ToListAsync());//it had the error which states that Cannot implicitly convert type 'System.Web.Mvc.ViewResult' to 'RegLog.Controllers.IActionResult'
}
}
答案 0 :(得分:1)
导入RegLog.Controllers
错误。该软件包来自另一个框架。确保使用本教程中的导入using System.Web.Mvc;
或using Microsoft.AspNetCore.Mvc;
。
来源:https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.actionresult?view=aspnet-mvc-5.2