Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b747c5

Browse files
Product item partial added
1 parent 9fe647a commit 2b747c5

File tree

4 files changed

+38
-148
lines changed

4 files changed

+38
-148
lines changed

‎AspnetRunBasics/Pages/Index.cshtml

Lines changed: 8 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
</div>
2828
</div>
2929
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
30-
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
31-
<span class="sr-only">Previous</span>
32-
</a>
33-
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
34-
<span class="carousel-control-next-icon" aria-hidden="true"></span>
3530
<span class="sr-only">Next</span>
3631
</a>
3732
</div>
@@ -67,74 +62,10 @@
6762
</div>
6863
<div class="card-body">
6964
<div class="row">
70-
<div class="col-sm">
71-
<div class="card">
72-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
73-
<div class="card-body">
74-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
75-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
76-
<div class="row">
77-
<div class="col">
78-
<p class="btn btn-danger btn-block">99.00 $</p>
79-
</div>
80-
<div class="col">
81-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
82-
</div>
83-
</div>
84-
</div>
85-
</div>
86-
</div>
87-
<div class="col-sm">
88-
<div class="card">
89-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
90-
<div class="card-body">
91-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
92-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
93-
<div class="row">
94-
<div class="col">
95-
<p class="btn btn-danger btn-block">99.00 $</p>
96-
</div>
97-
<div class="col">
98-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
99-
</div>
100-
</div>
101-
</div>
102-
</div>
103-
</div>
104-
<div class="col-sm">
105-
<div class="card">
106-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
107-
<div class="card-body">
108-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
109-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
110-
<div class="row">
111-
<div class="col">
112-
<p class="btn btn-danger btn-block">99.00 $</p>
113-
</div>
114-
<div class="col">
115-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
116-
</div>
117-
</div>
118-
</div>
119-
</div>
120-
</div>
121-
<div class="col-sm">
122-
<div class="card">
123-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
124-
<div class="card-body">
125-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
126-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
127-
<div class="row">
128-
<div class="col">
129-
<p class="btn btn-danger btn-block">99.00 $</p>
130-
</div>
131-
<div class="col">
132-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
133-
</div>
134-
</div>
135-
</div>
136-
</div>
137-
</div>
65+
@foreach (var product in Model.ProductList)
66+
{
67+
<partial name="_ProductItemPartial" model="@product" />
68+
}
13869
</div>
13970
</div>
14071
</div>
@@ -151,74 +82,10 @@
15182
</div>
15283
<div class="card-body">
15384
<div class="row">
154-
<div class="col-sm">
155-
<div class="card">
156-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
157-
<div class="card-body">
158-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
159-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
160-
<div class="row">
161-
<div class="col">
162-
<p class="btn btn-danger btn-block">99.00 $</p>
163-
</div>
164-
<div class="col">
165-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
166-
</div>
167-
</div>
168-
</div>
169-
</div>
170-
</div>
171-
<div class="col-sm">
172-
<div class="card">
173-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
174-
<div class="card-body">
175-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
176-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
177-
<div class="row">
178-
<div class="col">
179-
<p class="btn btn-danger btn-block">99.00 $</p>
180-
</div>
181-
<div class="col">
182-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
183-
</div>
184-
</div>
185-
</div>
186-
</div>
187-
</div>
188-
<div class="col-sm">
189-
<div class="card">
190-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
191-
<div class="card-body">
192-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
193-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
194-
<div class="row">
195-
<div class="col">
196-
<p class="btn btn-danger btn-block">99.00 $</p>
197-
</div>
198-
<div class="col">
199-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
200-
</div>
201-
</div>
202-
</div>
203-
</div>
204-
</div>
205-
<div class="col-sm">
206-
<div class="card">
207-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
208-
<div class="card-body">
209-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
210-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
211-
<div class="row">
212-
<div class="col">
213-
<p class="btn btn-danger btn-block">99.00 $</p>
214-
</div>
215-
<div class="col">
216-
<a href="cart.html" class="btn btn-success btn-block">Add to cart</a>
217-
</div>
218-
</div>
219-
</div>
220-
</div>
221-
</div>
85+
@foreach (var product in Model.ProductList)
86+
{
87+
<partial name="_ProductItemPartial" model="@product" />
88+
}
22289
</div>
22390
</div>
22491
</div>

‎AspnetRunBasics/Pages/Index.cshtml.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading.Tasks;
4+
using AspnetRunBasics.Repositories;
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.AspNetCore.Mvc.RazorPages;
7-
using Microsoft.Extensions.Logging;
87

98
namespace AspnetRunBasics.Pages
109
{
1110
public class IndexModel : PageModel
1211
{
13-
private readonly ILogger<IndexModel>_logger;
12+
private readonly IProductRepository_productRepository;
1413

15-
public IndexModel(ILogger<IndexModel>logger)
14+
public IndexModel(IProductRepositoryproductRepository)
1615
{
17-
_logger = logger;
16+
_productRepository = productRepository??thrownewArgumentNullException(nameof(productRepository));
1817
}
18+
19+
public IEnumerable<Entities.Product> ProductList { get; set; } = new List<Entities.Product>();
1920

20-
public voidOnGet()
21+
public asyncTask<IActionResult>OnGetAsync()
2122
{
22-
23+
ProductList = await _productRepository.GetProductListAsync();
24+
return Page();
2325
}
2426
}
2527
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@model Product
2+
3+
<div class="col-sm">
4+
<div class="card">
5+
<a asp-page="ProductDetail" asp-route-productId="@Model.Id"><img asp-append-version="true" class="card-img-top" src="~/images/product/@Model.ImageFile" alt=""></a>
6+
<div class="card-body">
7+
<h4 class="card-title"><a asp-page="ProductDetail" asp-route-productId="@Model.Id" class="color-main">@Model.Name</a></h4>
8+
<p class="card-text">@Model.Summary</p>
9+
<div class="row">
10+
<div class="col">
11+
<p class="btn btn-danger btn-block">@Model.Price $</p>
12+
</div>
13+
<div class="col">
14+
<a asp-page="Cart" asp-route-productId="@Model.Id" class="btn btn-success btn-block">Add to Cart</a>
15+
</div>
16+
</div>
17+
</div>
18+
</div>
19+
</div>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
@using AspnetRunBasics
2+
@using AspnetRunBasics.Entities
23
@namespace AspnetRunBasics.Pages
34
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
5+
@addTagHelper *, AspnetRunBasics

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /