I working on the View Component in ASP Net Core MVC. Here my view components
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();
}
I dont know why the error said could not find 'Invoke' or 'InvokeAsync' and the website show the problem is from HomeLayout which where i put MenuViewComponent
Here my 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);
}
}
(https://i.sstatic.net/oftjp.jpg)
Can you guys know the problems? I really need help. Thanks
public CartViewComponent(GiaydepContext context) { _context = context; } public IViewComponentResult Ivoke() { if (Total() == 0) {
Your CartViewComponent
has an Ivoke
method, not an Invoke
method.