Skip to content

Commit aa93d2a

Browse files
committed
Blazor Pages
1 parent 7f62c07 commit aa93d2a

10 files changed

Lines changed: 114 additions & 4 deletions

.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public IActionResult Index([FromQuery] string selectedManufacturer)
2828
Manufacturer = _context.Manufacturers.Select(m=>m.ManufacturerName).Distinct(),
2929
// 모든 제조사에 대해중복 없이
3030
SelectedManufacturer = selectedManufacturer
31-
// 인자로 들어온 현재 제조사값을 할당
31+
// 인자로 들어온 현재 제조사값을 할당*
3232
});
3333
}
3434
// views에 Home에 index.cshtml에 찾아 랜더링

.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/Controllers/ProductsController_With_Entity_FrameWork.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,5 @@ private bool ProductExists(int id)
165165
{
166166
return _context.Products.Any(e => e.ProductId == id);
167167
}
168-
}
168+
}
169169
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@page "/pages"
2+
@model AspNetCoreBlazorEmpty.Pages.IndexModel
3+
4+
<h4 class="bg-primary text-white text-center p-2">Product</h4>
5+
<table class="table table-sm table-bordered table-striped">
6+
<thead>
7+
<tr>
8+
<th>ID</th>
9+
<th>Name (Price)</th>
10+
<th>Category</th>
11+
<th>Manufacturer</th>
12+
</tr>
13+
</thead>
14+
<tbody>
15+
@foreach (Product p in Model?.Product ?? Enumerable.Empty<Product>())
16+
{
17+
<tr class="@Model?.GetClass(p.ProductManufacturer?.ManufacturerName)">
18+
<td>@p.ProductId</td>
19+
<td>@p.ProductName, @p.ProductPrice?.ToString("#,##0")</td>
20+
<td>@p.ProductCategory.CategoryName</td>
21+
<td>@p.ProductManufacturer?.ManufacturerName</td>
22+
</tr>
23+
}
24+
</tbody>
25+
</table>
26+
27+
<form asp-action="Index" method="get">
28+
<div class="form-group">
29+
<label for="selectedManufacturer">Manufacturer</label>
30+
<select name="selectedManufacturer" class="form-control">
31+
<option disabled selected>Select Manufacturer</option>
32+
@foreach (string Manufacturer in Model?.Manufacturer ?? Enumerable.Empty<string>())
33+
{
34+
<option selected="@(Manufacturer == Model?.SelectedManufacturer)">
35+
@Manufacturer
36+
</option>
37+
}
38+
</select>
39+
</div>
40+
<button class="btn btn-primary mt-2" type="submit">Select</button>
41+
</form>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using AspNetCoreBlazorEmpty.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
using Microsoft.EntityFrameworkCore;
5+
6+
using System;
7+
8+
namespace AspNetCoreBlazorEmpty.Pages
9+
{
10+
public class IndexModel : PageModel
11+
{
12+
private BlazorTDBContext context;
13+
14+
public IndexModel(BlazorTDBContext dbContext)
15+
{
16+
context = dbContext;
17+
}
18+
19+
public IEnumerable<Product> Product { get; set; } = Enumerable.Empty<Product>();
20+
public IEnumerable<string> Manufacturer { get; set; } = Enumerable.Empty<string>();
21+
22+
[FromQuery]
23+
public string SelectedManufacturer { get; set; } = String.Empty;
24+
25+
public void OnGet()
26+
{
27+
Product = context.Products.Include(p => p.ProductCategory).Include(p => p.ProductManufacturer);
28+
Manufacturer = context.Manufacturers.Select(m => m.ManufacturerName).Distinct();
29+
}
30+
31+
public string GetClass(string? Manufacturer) => SelectedManufacturer == Manufacturer ? "bg-info text-white" : "";
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>@ViewBag.Title</title>
5+
<link href="/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
6+
</head>
7+
<body>
8+
<div class="m-2">
9+
<h5 class="bg-secondary text-white text-center p-2">Razor Page</h5>
10+
@RenderBody()
11+
</div>
12+
</body>
13+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
2+
@using AspNetCoreBlazorEmpty.Models
3+
@using Microsoft.AspNetCore.Mvc.RazorPages
4+
@using Microsoft
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_Layout";
3+
}

.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/obj/Debug/net8.0/AspNetCoreBlazorEmpty.AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[assembly: System.Reflection.AssemblyCompanyAttribute("AspNetCoreBlazorEmpty")]
1616
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
1717
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
18-
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+df6dcb8052dba848535ddab84bb546b0dd96bdc6")]
18+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7f62c07ee1ed25353e2095a0607a9ec22b3cf968")]
1919
[assembly: System.Reflection.AssemblyProductAttribute("AspNetCoreBlazorEmpty")]
2020
[assembly: System.Reflection.AssemblyTitleAttribute("AspNetCoreBlazorEmpty")]
2121
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a45a511502740d487517898df06a86b76bea389c80e83df36c681be2a1c59764
1+
feed177cb52d7a7676f8927ff1e26d786c2ca2c77e958dc26df771e5765d14ce

.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/obj/Debug/net8.0/AspNetCoreBlazorEmpty.GeneratedMSBuildEditorConfig.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ build_property._RazorSourceGeneratorDebug =
2828
build_property.EffectiveAnalysisLevelStyle = 8.0
2929
build_property.EnableCodeStyleSeverity =
3030

31+
[F:/Csharp.NET/Csharp.NET/.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/Pages/Index.cshtml]
32+
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcSW5kZXguY3NodG1s
33+
build_metadata.AdditionalFiles.CssScope =
34+
35+
[F:/Csharp.NET/Csharp.NET/.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/Pages/_Layout.cshtml]
36+
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcX0xheW91dC5jc2h0bWw=
37+
build_metadata.AdditionalFiles.CssScope =
38+
39+
[F:/Csharp.NET/Csharp.NET/.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/Pages/_ViewImports.cshtml]
40+
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcX1ZpZXdJbXBvcnRzLmNzaHRtbA==
41+
build_metadata.AdditionalFiles.CssScope =
42+
43+
[F:/Csharp.NET/Csharp.NET/.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/Pages/_ViewStart.cshtml]
44+
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcX1ZpZXdTdGFydC5jc2h0bWw=
45+
build_metadata.AdditionalFiles.CssScope =
46+
3147
[F:/Csharp.NET/Csharp.NET/.NET ASP/AspNetCoreBlazorEmpty/AspNetCoreBlazorEmpty/Views/Home/Index.cshtml]
3248
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcSG9tZVxJbmRleC5jc2h0bWw=
3349
build_metadata.AdditionalFiles.CssScope =

0 commit comments

Comments
 (0)