osyris zosar

osyris zosar

  • NA
  • 289
  • 24k

Passing database data to _loginPartial.cshtml

Apr 21 2021 9:42 PM
I am trying to pass a the number of products that are added to the shopping card
it needs to show in the  _loginPartial.cshtml Top header bar
but it seems more complicated than i thought
 
  1. @{  
  2.     var userid = HttpContext.Request.Cookies["Shopping-card"];  
  3.     string getcount = _context.shoppingCard.Where(x => x.ClientId == Guid.Parse(userid)).Count().ToString();  
  4. }  
  5. <ul class="navbar-nav">  
  6.   
  7.     <li class="nav-item">  
  8.         <a class="nav-link text-dark" asp-controller="Home" asp-action="Checkout"> Shoppingcard @getcount </a>  
  9.     </li>  
 
 Im getting a error on the "HttpContext" 
 
so i tried to create a function in the controller and then pass it into the  _loginPartial.cshtml
 
  1. public string getShoppingbackcount()  
  2. {  
  3.     var userid = HttpContext.Request.Cookies["Shopping-card"];  
  4.     string getcount = _context.shoppingCard.Where(x => x.ClientId == Guid.Parse(userid)).Count().ToString();  
  5.     return getcount;  
  6.     }  
 That did not work either. even when i use the @using Webshop.Controllers;
im getting  allot of error saying that "getShoppingbackcount()" does not exist
 
I am out of ideas to get database date passed to the  _loginPartial.cshtml

Answers (5)