9.2.1 Removing Items from the Cart; Listing 9-4 Introducing a Remove Button to the Index.cshtml File

chap09
Jason Zhu 2021-09-22 11:15:00 +10:00
parent a8154783e7
commit 5636a37f58
1 changed files with 17 additions and 1 deletions

View File

@ -4,8 +4,14 @@
ViewBag.Title = "Sports Store: Your Cart"; ViewBag.Title = "Sports Store: Your Cart";
} }
@*Add style tag of cart table*@
<style>
#cartTable td { vertical-align: middle; }
</style>
<h2>Your cart</h2> <h2>Your cart</h2>
<table class="table"> @*Add id*@
<table id="cartTable" class="table">
<thead> <thead>
<tr> <tr>
<th>Quantity</th> <th>Quantity</th>
@ -23,6 +29,16 @@
<td class="text-right"> <td class="text-right">
@((line.Quantity * line.Product.Price).ToString("c")) @((line.Quantity * line.Product.Price).ToString("c"))
</td> </td>
@*Add button*@
<td>
@using (Html.BeginForm("RemoveFromCart", "Cart"))
{
@Html.Hidden("ProductId", line.Product.ProductID)
@Html.HiddenFor(x => x.ReturnUrl)
<input class="btn btn-sm btn-warning"
type="submit" value="Remove" />
}
</td>
</tr> </tr>
} }
</tbody> </tbody>