TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
@{
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
Reply
Answers (
5
)
Wpf Mvvm Multiple (2) views and the same instance of a viewmodel
How to Select default value in dropdown in mvc base on condition