Skip to content
Loading
Passing database data to _loginPartial.cshtmlThe "HttpContext" is what is causing the problem if i could make HttpContext to work or get the value of the cookie "Shopping-card"in a other way this would be much easier because i need the Cookie value in order to link the shoppingcard wih the right user.
 
any ideas?
+1
  • when products are added then save the count in Session then easily read that in your partial view.
    1. public void AddProducts()  
    2. {  
    3. var userid = HttpContext.Request.Cookies["Shopping-card"];    
    4.     string getcount = _context.shoppingCard.Where(x => x.ClientId == Guid.Parse(userid)).Count().ToString();   
    5. Session["Count"]=getCount;  
    6. }  
    7. // partial view
    8. @session["Count"].ToString();
     
    +2
  • Asma Khalid
    Attach ViewModel with _loginPartial.cshtml
     
    Mark answer as accepted if helpful
     
    Thanks & Regards,
    Asma Khalid
    +2
  • Satya Karki
    Hi, you can use ViewBag or ViewData or TampData. 
    In your controller action, you can set your Count in ViewBag and in your partial view you can show it.
     
    Sample code for ViewBag 
    1. public ActionResult Index()  
    2. {  
    3.  var userid = HttpContext.Request.Cookies["Shopping-card"];    
    4.     string getcount = _context.shoppingCard.Where(x => x.ClientId == Guid.Parse(userid)).Count().ToString();    
    5.   
    6. ViewBag.count = getcount;  
    7.   return View();  
    8. }  
    There are different ways. you can check below link
     
    https://www.codeproject.com/Tips/898017/Different-Ways-to-Pass-Data-to-Partial-View 
    +2