我正在研究 ASP Net Core MVC 中的视图组件。这是我的视图组件
public CartViewComponent(GiaydepContext context)
{
_context = context;
}
public IViewComponentResult Ivoke()
{
if (Total() == 0)
{
ViewBag.Total = 0;
ViewBag.Totalmoney = 0;
return View();
}
ViewBag.Total = Total();
ViewBag.Totalmoney = TotalMoney();
return View();
}
我不知道为什么错误说找不到“Invoke”或“InvokeAsync”,并且网站显示问题来自我放置 MenuViewComponent 的 HomeLayout
这是我的 MenuViewComponent
public class MenuViewComponent : ViewComponent
{
private readonly GiaydepContext _context;
public MenuViewComponent (GiaydepContext context)
{
_context = context;
}
public IViewComponentResult Invoke()
{
var lstSP = _context.SanPhams
.Include(n => n.ManhaccNavigation)
.Include(n => n.MaloaispNavigation);
return View(lstSP);
}
}
你们知道问题所在吗? 我真的需要帮助。 谢谢
public CartViewComponent(GiaydepContext context) { _context = context; } public IViewComponentResult Ivoke() { if (Total() == 0) {
您的
CartViewComponent
有一个 Ivoke
方法,而不是 Invoke
方法。