无法将类型'System.Web.Mvc.ViewResult'隐式转换为'RegLog.Controllers.IActionResult'

时间:2019-03-15 09:21:33

标签: c# asp.net-core-mvc

由于我正在为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'
        }
    }

1 个答案:

答案 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