Skip to content

Commit eadf2a6

Browse files
committed
Add sample for blazor multi render
1 parent 56c9549 commit eadf2a6

File tree

15 files changed

+144
-12
lines changed

15 files changed

+144
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Samples for ASP.NET Core 6.0 (474)
1+
# Samples for ASP.NET Core 6.0 (475)
22

3-
Samples for ASP.NET Core **8.0 Preview 4** is available [here](/projects/.net8) (12).
3+
Samples for ASP.NET Core **8.0 Preview 6** is available [here](/projects/.net8) (13).
44

55
Samples for ASP.NET Core **7.0** is available [here](/projects/.net7) (45).
66

projects/.net8/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# ASP.NET 8.0 Preview 6 (12)
1+
# ASP.NET 8.0 Preview 6 (13)
22

33
These samples require [.NET 8.0 Preview 6](https://github.com/dotnet/installer#table).
44

5-
65
* [QuickGrid One](QuickGridOne)
76

87
This sample demonstrates a simple usage of QuickGrid component displaying int, string, date, and boolean data types.
@@ -31,6 +30,9 @@ These samples require [.NET 8.0 Preview 6](https://github.com/dotnet/installer#t
3130

3231
This sample demonstrates the new section functionality using `SectionOutlet` to mark a section and `SectionContent` to supply the content to a section.
3332

33+
* [RazorComponentSeven](RazorComponentSeven)
34+
This sample demonstrates a Razor Component Page SSR (Server Side Render) hosting Razor Component with Blazor Server Side (interactive) and Blazor Streaming Rendering.
35+
3436
* [Request Timeout](request-timeout)
3537

3638
This sample demonstrates how to configure a request timeout.
@@ -50,5 +52,3 @@ These samples require [.NET 8.0 Preview 6](https://github.com/dotnet/installer#t
5052
* [SlimBuilder](slim-builder)
5153

5254
`WebApplication.CreateSlimBuilder` creates `WebApplicationBuilder` with minimal configuration defaults.
53-
54-
<!-- https://github.com/dotnet/aspnetcore/tree/main/src/Components/Samples/BlazorUnitedApp -->
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
@page "/"
22

3-
Good morning hello world
4-
53
<Greetings Message="Hello World" />

projects/.net8/RazorComponentOne/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
var app = builder.Build();
55

6-
app.MapRazorComponents<RazorComponentOne.Shared.MainLayout>();
6+
app.MapRazorComponents<RazorComponentOne.Pages.App>();
77
app.Run();
88

99

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@inherits LayoutComponentBase
2-
32
<!doctype html>
43
<html lang="en">
54
<head>
@@ -9,8 +8,6 @@
98
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp" crossorigin="anonymous">
109
</head>
1110
<body>
12-
This text is from the layout but the body is missing
13-
<br/>
1411
@Body
1512
</body>
1613
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
6+
<title>Blazor Multi Render</title>
7+
<base href="/" />
8+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
9+
<HeadOutlet />
10+
</head>
11+
<body>
12+
<Router AppAssembly="@typeof(App).Assembly">
13+
<Found Context="routeData">
14+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
15+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
16+
</Found>
17+
<NotFound>
18+
<PageTitle>Not found</PageTitle>
19+
<LayoutView Layout="@typeof(MainLayout)">
20+
<p role="alert">Sorry, there's nothing at this address.</p>
21+
</LayoutView>
22+
</NotFound>
23+
</Router>
24+
25+
<script src="_framework/blazor.web.js" suppress-error="BL9992"></script>
26+
</body>
27+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@page "/"
2+
3+
<h1>Blazor Multi Render</h1>
4+
5+
@_message
6+
7+
<div class="row">
8+
<div class="col-md-4">
9+
<p class="mb-3">
10+
This button will not work because this Razor component is statically rendered
11+
</p>
12+
<button type="button" class="btn btn-primary" @onclick="ShowMessage">Show Message</button>
13+
</div>
14+
<div class="col-md-4">
15+
<Numbers />
16+
</div>
17+
<div class="col-md-4">
18+
<p class="mb-3">
19+
This button will work because this Razor component is powered by Server Side Blazor
20+
</p>
21+
<Interactive />
22+
</div>
23+
</div>
24+
25+
@code {
26+
string _message = string.Empty;
27+
28+
void ShowMessage()
29+
{
30+
_message = "This won't work";
31+
}
32+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@attribute [RenderModeServer]
2+
3+
@_message
4+
5+
<button type="button" class="btn btn-primary" @onclick="ShowMessage">Show Message</button>
6+
7+
@code {
8+
string _message = string.Empty;
9+
10+
void ShowMessage()
11+
{
12+
_message = "Current Time UTC " + DateTime.UtcNow;
13+
}
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@attribute [StreamRendering(true)]
2+
3+
@if (_numbers is null)
4+
{
5+
<p>Loading numbers (wait for 6 seconds) ...</p>
6+
}
7+
else
8+
{
9+
<ul>
10+
@foreach(var i in _numbers)
11+
{
12+
<li>@i</li>
13+
}
14+
</ul>
15+
}
16+
17+
@code
18+
{
19+
List<int> _numbers;
20+
21+
protected override async Task OnInitializedAsync()
22+
{
23+
await Task.Delay(6_000); //six seconds
24+
25+
_numbers = Enumerable.Range(0,100).ToList();
26+
}
27+
}
28+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var builder = WebApplication.CreateBuilder();
2+
builder.Services.AddRazorComponents()
3+
.AddServerComponents();
4+
5+
var app = builder.Build();
6+
app.MapRazorComponents<RazorComponentSeven.App>();
7+
app.Run();
8+
9+

0 commit comments

Comments
 (0)