asp.netasp.net-mvcasp.net-corerazor-pagesasp.net-core-viewcomponent

Could not find an 'Invoke' or 'InvokeAsync' method for the view component 'Shoes.Components.CartViewComponent'


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();
 }

Here is the path to Razor 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) Here where I put the Menuviewcompoent And the error

Can you guys know the problems? I really need help. Thanks


Solution

  • public CartViewComponent(GiaydepContext context)  
    {
        _context = context;
    }
    public IViewComponentResult Ivoke()
    {
        if (Total() == 0) 
        {
    

    Your CartViewComponent has an Ivoke method, not an Invoke method.