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();
- }
- <ul class="navbar-nav">
-
- <li class="nav-item">
- <a class="nav-link text-dark" asp-controller="Home" asp-action="Checkout"> Shoppingcard @getcount </a>
- </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
- 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