Shopping cart

3 279 0
Shopping cart

Đang tải... (xem toàn văn)

Thông tin tài liệu

Shopping cart Sử dụng sở liệu Northwind để thực hành Shopping Cart Bước Tạo dự án Bước Add ADO.NET Entity Data Model đặt tên hình vẽ, add bảng vào Model Bước Bổ sung Action method vào HomeController sau phương thức: Index, AddToCart, YourCart, RemoveItem Bước Sửa lại code Home/Index.cshtml sau @model IEnumerable @{ ViewBag.Title = "Index"; } Index @foreach (var p in Model) { Product ID: @p.ProductID Product ID: @p.ProductName Product ID: @p.UnitPrice Product ID: @p.Category.CategoryName @Html.ActionLink("Add to cart", "AddToCart", "Home", new { @Id = @p.ProductID }, new { @class = "btn btn-primary" }) } Bước Thêm view với nội dung sau @{ ViewBag.Title = "YourCart"; } YourCart @{ var cart = Session["cart"] as ShoppingCart.Controllers.ShoppingCart; } Product ID Quantity Price Action @for (int i = 0; i < cart.CartItems.Rows.Count; i++) { @cart.CartItems.Rows[i][0].ToString() @cart.CartItems.Rows[i][1].ToString() @cart.CartItems.Rows[i][2].ToString() @Html.ActionLink("Delete","RemoveItem", "Home", new { @Id = cart.CartItems.Rows[i][0].ToString() }, new { @class = "btn btn-primary" }) } Bước Biên dịch chạy thử dự án

Ngày đăng: 28/06/2016, 19:26

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan