Uttam Kumar

Uttam Kumar

  • NA
  • 12
  • 708

Shopping Cart is not working properly in Asp.netCoreRazor2.0

Jan 14 2019 3:19 AM
Shopping Cart Page displays only one item in Asp.net Core 2.0 Razor Pages
 
There is a problem When I clicked on Add to cart Button ,only one item is displayed and previous one is deleted .I have four Boostrap tab,on every click I am passing tab&id .How to fix this problem I think its very simple but I am new in Asp.net Core.Any help it would be great appreciate.Following are more details about my appication, I've attached as a zip file.
 
This is my Index.cshtml file
  1.     
  2. <div class="tab4">    
  3.                     @foreach (var item in Model.FootwereList)    
  4.                     {    
  5.                         <div class="col-md-3 product-men">    
  6.                             <div class="men-pro-item simpleCart_shelfItem">    
  7.                                 <div class="men-thumb-item">    
  8.                                     <img src="@Html.DisplayFor(modelItem => item.ImageaFront)" alt="" class="pro-image-front">    
  9.                                     <img src="@Html.DisplayFor(modelItem => item.ImageBack)" alt="" class="pro-image-back">    
  10.                                     <div class="men-cart-pro">    
  11.                                         <div class="inner-men-cart-pro">    
  12.                                             <a asp-page="/single" asp-route-tab="@item.tab" asp-route-id="@item.ProductID" class="link-product-add-cart">Quick Viewa>    
  13.                                         div>    
  14.                                     div>    
  15.                                     <span class="product-new-top">Newspan>    
  16.     
  17.                                 div>    
  18.                                 <div class="item-info-product ">    
  19.                                     <h4><a href="single.html">@Html.DisplayFor(modelItem => item.ProductName)a>h4>    
  20.                                     <div class="info-product-price">    
  21.                                         <span class="item_price">[email protected](modelItem => item.OriginalPrice)span>    
  22.                                         <del>[email protected](modelItem => item.FalsePrice)del>    
  23.                                     div>    
  24.                                     <div class="snipcart-details top_brand_home_details item_add single-item hvr-outline-out button2">    
  25.                                         <form action="/shopping_Cart" method="post">    
  26.                                                 
  27.                                             fieldset>    
  28.                                         form>    
  29.                                     div>    
  30.                                     <div class="inner-men-cart-pro">    
  31.                                         <a asp-page="/shopping_Cart" asp-route-tab="@item.tab" asp-route-id="@item.ProductID" class="link-product-add-cart">Add to carta>    
  32.                                     div>    
  33.                                 div>    
  34.                             div>    
  35.                         div>    
  36.                     }    
  37.                 div>    
This is my shopping_cart.cshtml file
  1. @page    
  2. @model EliteShopping.Pages.Shopping.shopping_CartModel    
  3. @{    
  4. }    
  5. <h2 style="position:center;">Your Shopping Carth2>    
  6.     
  7.     @*<p>    
  8.         <a asp-page="Customer">Create New Customera>    
  9.     p>*@    
  10.     <table class="table">    
  11.         <thead>    
  12.             <tr>    
  13.                 <th>    
  14.                     @Html.DisplayName("Image")    
  15.                 th>    
  16.                 <th>    
  17.                     @Html.DisplayName("Name")    
  18.                 th>    
  19.                 <th>    
  20.                     @Html.DisplayName("Price")    
  21.                 th>    
  22.                   
  23.             tr>    
  24.         thead>    
  25.         <tbody>    
  26.             @foreach (var item in Model.FootwereList)    
  27.             {    
  28.                 <tr>    
  29.                     <td>    
  30.                         @Html.DisplayFor(modelItem => item.ImageaFront)    
  31.                     td>    
  32.                     <td>    
  33.                         @Html.DisplayFor(modelItem => item.ProductName)    
  34.                     td>    
  35.                     <td>    
  36.                         @Html.DisplayFor(modelItem => item.OriginalPrice)    
  37.                     td>    
  38.                        
  39.                     <td>    
  40.                         <a asp-page="./EditCustomer" asp-route-id="@item.ProductID">Edit Cart Itema> |    
  41.                         <a asp-page="./AllCustomer" onclick="return confirm('Are you sure you want to delete this item?');" asp-page-handler="Delete" asp-route-id="@item.ProductID">Delete Itema>    
  42.                     td>    
  43.                 tr>    
  44.             }    
  45.         tbody>    
  46.     table>   
This is my shopping_cart.csfile 
  1. using EliteShopping.Models;  
  2. using Microsoft.AspNetCore.Mvc;  
  3. using Microsoft.AspNetCore.Mvc.RazorPages;  
  4. using RazorPagesDemo.Models;  
  5. using System.Collections.Generic;  
  6. using System.Linq;  
  7.   
  8. namespace EliteShopping.Pages.Shopping  
  9. {  
  10.   
  11.     public class shopping_CartModel : PageModel  
  12.     {  
  13.         DatabaseContext _Context;  
  14.         public shopping_CartModel(DatabaseContext databasecontext)  
  15.         {  
  16.             _Context = databasecontext;  
  17.         }  
  18.           
  19.         public List FootwereList { getset; }  
  20.   
  21.         [BindProperty]  
  22.         public Footwere Footwere { getset; }  
  23.   
  24.   
  25.         public void OnGet(int id, string tab)  
  26.   
  27.         {     //for Footwere  
  28.             var Footwere = (from FootwereList in _Context.FootwereTB  
  29.                             where FootwereList.ProductID == id & FootwereList.tab == tab  
  30.                             select FootwereList).ToList();  
  31.   
  32.             FootwereList = Footwere;  
  33.         }  
  34.   
  35.           
  36.         
  37.     }  
  38.  }