29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

// ...other action methods omitted for brevity...<br />

}<br />

The last step to display the contents of the cart is to create the new view. Right-click on the Index action method and select<br />

Add View from the pop-up menu. Set the name to Index and click the OK button to create the Index.cshtml view<br />

file. Edit the view to match the contents shown in Listing 8-17.<br />

Listing 8-17. The Contents of the Index.cshtml File<br />

@model SportsStore.WebUI.Models.CartIndexViewModel<br />

@{<br />

}<br />

ViewBag.Title = "Sports Store: Your Cart";<br />

Your cart<br />

<br />

<br />

<br />

Quantity<br />

Item<br />

Price<br />

Subtotal<br />

<br />

<br />

<br />

@foreach (var line in Model.Cart.Lines) {<br />

<br />

@line.Quantity<br />

@line.Product.Name<br />

@line.Product.Price.ToString("c")<br />

<br />

<br />

@((line.Quantity * line.Product.Price).ToString("c"))<br />

<br />

<br />

}<br />

<br />

<br />

<br />

Total:<br />

<br />

@Model.Cart.ComputeTotalValue().ToString("c")<br />

<br />

<br />

<br />

<br />

<br />

Continue<br />

shopping<br />

<br />

The view enumerates the lines in the cart and adds rows for each of them to an HTML table, along with the total cost per line<br />

225

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!