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
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
<
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 View
a
>
div
>
div
>
<
span
class
=
"product-new-top"
>
New
span
>
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 cart
a
>
div
>
div
>
div
>
div
>
}
div
>
This is my shopping_cart.cshtml file
@page
@model EliteShopping.Pages.Shopping.shopping_CartModel
@{
}
<
h2
style
=
"position:center;"
>
Your Shopping Cart
h2
>
@*
<
p
>
<
a
asp-page
=
"Customer"
>
Create New Customer
a
>
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 Item
a
>
|
<
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 Item
a
>
td
>
tr
>
}
tbody
>
table
>
This is my shopping_cart.csfile
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;
}
}
}
Attachment:
Shopping_Cart_Page_dispalys_only_one_item_in_Asp.net_Core_2.0_Razor_Pages.zip
Reply
Answers (
0
)
Related to gridview OnselectedIndexChanged
I have to use query string passed in url to some link.