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
- @{
- var userid = HttpContext.Request.Cookies["Shopping-card"];
- string getcount = _context.shoppingCard.Where(x => x.ClientId == Guid.Parse(userid)).Count().ToString();
- }
- class
-
- class
="nav-item"> - class="nav-link text-dark" asp-controller="Home" asp-action="Checkout"> Shoppingcard @getcount
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
- public string getShoppingbackcount()
- {
- var userid = HttpContext.Request.Cookies["Shopping-card"];
- string getcount = _context.shoppingCard.Where(x => x.ClientId == Guid.Parse(userid)).Count().ToString();
- return getcount;
- }
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

Satya KarkiRank #78 · 24.6K reputationPosted Apr 22, 2021, 1:39 AM EDT
Asma KhalidRank #160 · 14.7K reputationPosted Apr 22, 2021, 3:21 AM EDT
Aarti GuptaRank #5,944 · 281 reputationPosted Apr 22, 2021, 3:29 AM EDT
Satya KarkiRank #78 · 24.6K reputationPosted Apr 22, 2021, 11:10 AM EDT
osyris zosarRank #6,574 · 262 reputationPosted Apr 22, 2021, 10:15 AM EDT
class
="navbar-nav">