ASP.NET MVC - "Cannot await 'method group'" 和 "namespace name 'ASPNETCoreWebApplication' could not be found"

ASP.NET MVC - "Cannot await 'method group'", and "namespace name 'ASPNETCoreWebApplication' could not be found"

遇到 return View(await _context.Reviews.ToListAsync); 出现以下错误的问题:Cannot await 'method group'

我相信要使用 return View(await _context.Reviews.ToListAsync); 语句,我需要使用 using ASPNETCoreWebApplication.data(因此我包含它),但它 returns 一个错误:The type or namespace 'ASPNETCoreWebApplication' could not be found [...].

如果我删除 using <project_name>data,在 HomeController.cs)

中出现与上述 ApplicationDbContext 相同的错误

下面是我的HomeController.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ASPNETCoreWebApplication.Data; // "The type or namespace 'ASPNETCoreWebApplication' could not be found [...]"
using <project_name>.Data;
using Microsoft.EntityFrameworkCore;

namespace <project_name>.Controllers
{
    public class HomeController : Controller
    {
        private readonly ApplicationDbContext _context;

        public HomeController(ApplicationDbContext context)
        {
            _context = context;
        }

        public async Task<IActionResult> Reviews()
        {
            // "Cannot await 'method group'"
            return View(await _context.Reviews.ToListAsync);
        }

        public IActionResult Error()
        {
            return View();
        }
    }
}

如果可能相关,这是我的 Reviews.cs 型号:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace <project_name>.Models
{
    public class Reviews
    {
        public int Id { get; set; }
        public string Date { get; set; }
        public string Name { get; set; }
        public string Heading { get; set; }
        public string Restaurant { get; set; }
        public string Comment { get; set; }
        public int Rating { get; set; }
        public int Agree { get; set; }
        public int Disagree { get; set; }
    }
}

HomeController.cs

不要犯忘记括号的新手错误:

public async Task<IActionResult> Reviews()
        {
            return View(await _context.Reviews.ToListAsync());
        }