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
- <div class="tab4">
- @foreach (var item in Model.FootwereList)
- {
- <div class="col-md-3 product-men">
- <div class="men-pro-item simpleCart_shelfItem">
- <div class="men-thumb-item">
- <img src="@Html.DisplayFor(modelItem => item.ImageaFront)" alt="" class="pro-image-front">
- <img src="@Html.DisplayFor(modelItem => item.ImageBack)" alt="" class="pro-image-back">
- <div class="men-cart-pro">
- <div class="inner-men-cart-pro">
- <a asp-page="/single" asp-route-tab="@item.tab" asp-route-id="@item.ProductID" class="link-product-add-cart">Quick Viewa>
- div>
- div>
- <span class="product-new-top">Newspan>
- div>
- <div class="item-info-product ">
- <h4><a href="single.html">@Html.DisplayFor(modelItem => item.ProductName)a>h4>
- <div class="info-product-price">
- <span class="item_price">[email protected](modelItem => item.OriginalPrice)span>
- <del>[email protected](modelItem => item.FalsePrice)del>
- div>
- <div class="snipcart-details top_brand_home_details item_add single-item hvr-outline-out button2">
- <form action="/shopping_Cart" method="post">
- fieldset>
- form>
- div>
- <div class="inner-men-cart-pro">
- <a asp-page="/shopping_Cart" asp-route-tab="@item.tab" asp-route-id="@item.ProductID" class="link-product-add-cart">Add to carta>
- div>
- div>
- div>
- div>
- }
- div>
- @page
- @model EliteShopping.Pages.Shopping.shopping_CartModel
- @{
- }
- <h2 style="position:center;">Your Shopping Carth2>
- @*<p>
- <a asp-page="Customer">Create New Customera>
- p>*@
- <table class="table">
- <thead>
- <tr>
- <th>
- @Html.DisplayName("Image")
- th>
- <th>
- @Html.DisplayName("Name")
- th>
- <th>
- @Html.DisplayName("Price")
- th>
- tr>
- thead>
- <tbody>
- @foreach (var item in Model.FootwereList)
- {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.ImageaFront)
- td>
- <td>
- @Html.DisplayFor(modelItem => item.ProductName)
- td>
- <td>
- @Html.DisplayFor(modelItem => item.OriginalPrice)
- td>
- <td>
- <a asp-page="./EditCustomer" asp-route-id="@item.ProductID">Edit Cart Itema> |
- <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>
- td>
- tr>
- }
- tbody>
- table>
- using EliteShopping.Models;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- using RazorPagesDemo.Models;
- using System.Collections.Generic;
- using System.Linq;
- namespace EliteShopping.Pages.Shopping
- {
- public class shopping_CartModel : PageModel
- {
- DatabaseContext _Context;
- public shopping_CartModel(DatabaseContext databasecontext)
- {
- _Context = databasecontext;
- }
- public List
FootwereList { get; set; } - [BindProperty]
- public Footwere Footwere { get; set; }
- public void OnGet(int id, string tab)
- { //for Footwere
- var Footwere = (from FootwereList in _Context.FootwereTB
- where FootwereList.ProductID == id & FootwereList.tab == tab
- select FootwereList).ToList();
- FootwereList = Footwere;
- }
- }
- }
Replies
Know the answer? Post it — somebody with the same question will find it here.