Res*_*ACK 2 asp.net-mvc namespaces method-group
遇到一个问题,return View(await _context.Reviews.ToListAsync);
出现以下错误:Cannot await 'method group'
我相信要使用该return View(await _context.Reviews.ToListAsync);
语句,我需要使用using ASPNETCoreWebApplication.data
(因此我包含它),但它返回一个错误:The type or namespace 'ASPNETCoreWebApplication' could not be found [...]
。
如果我删除using <project_name>data
,则会出现与上面ApplicationDbContext
in相同的HomeController.cs
错误
以下是我的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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果可能相关,这是我的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; }
}
}
Run Code Online (Sandbox Code Playgroud)
在HomeController.cs
,
Res*_*ACK 16
不要犯忘记括号的菜鸟错误:
public async Task<IActionResult> Reviews()
{
return View(await _context.Reviews.ToListAsync());
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9148 次 |
最近记录: |