File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed
AspNetRunBasic/Pages/Product Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ @page
2+ @model AspNetRunBasic .Pages .Product .DetailsModel
3+ @{
4+ ViewData [" Title" ] = " Details" ;
5+ }
6+
7+ <h1 >Details</h1 >
8+
9+ <div >
10+ <h4 >Product</h4 >
11+ <hr />
12+ <dl class =" row" >
13+ <dt class =" col-sm-2" >
14+ @Html.DisplayNameFor(model => model.Product.Name)
15+ </dt >
16+ <dd class =" col-sm-10" >
17+ @Html.DisplayFor(model => model.Product.Name)
18+ </dd >
19+ <dt class =" col-sm-2" >
20+ @Html.DisplayNameFor(model => model.Product.Description)
21+ </dt >
22+ <dd class =" col-sm-10" >
23+ @Html.DisplayFor(model => model.Product.Description)
24+ </dd >
25+ <dt class =" col-sm-2" >
26+ @Html.DisplayNameFor(model => model.Product.UnitPrice)
27+ </dt >
28+ <dd class =" col-sm-10" >
29+ @Html.DisplayFor(model => model.Product.UnitPrice)
30+ </dd >
31+ <dt class =" col-sm-2" >
32+ @Html.DisplayNameFor(model => model.Product.Category)
33+ </dt >
34+ <dd class =" col-sm-10" >
35+ @Html.DisplayFor(model => model.Product.Category.Name)
36+ </dd >
37+ </dl >
38+ </div >
39+ <div >
40+ <a asp-page =" ./Edit" asp-route-productId =" @Model.Product.Id" >Edit</a > |
41+ <a asp-page =" ./Index" >Back to List</a >
42+ </div >
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Threading . Tasks ;
5+ using AspNetRunBasic . Repositories ;
6+ using Microsoft . AspNetCore . Mvc ;
7+ using Microsoft . AspNetCore . Mvc . RazorPages ;
8+
9+ namespace AspNetRunBasic . Pages . Product
10+ {
11+ public class DetailsModel : PageModel
12+ {
13+ private readonly IProductRepository _productRepository ;
14+
15+ public DetailsModel ( IProductRepository productRepository )
16+ {
17+ _productRepository = productRepository ?? throw new ArgumentNullException ( nameof ( productRepository ) ) ;
18+ }
19+
20+ public Entities . Product Product { get ; set ; }
21+
22+ public async Task < IActionResult > OnGetAsync ( int ? productId )
23+ {
24+ if ( productId == null )
25+ {
26+ return NotFound ( ) ;
27+ }
28+
29+ Product = await _productRepository . GetProductByIdAsync ( productId . Value ) ;
30+ if ( Product == null )
31+ {
32+ return NotFound ( ) ;
33+ }
34+ return Page ( ) ;
35+ }
36+
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments