Skip to content

Commit 07df763

Browse files
committed
add blazor components sample
1 parent 7ffce06 commit 07df763

11 files changed

+141
-15
lines changed

YAF.SampleApp/App.razor

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@using Microsoft.AspNetCore.Components.Routing
2+
3+
<Router AppAssembly="typeof(App).Assembly">
4+
<Found Context="routeData">
5+
<RouteView RouteData="routeData" />
6+
</Found>
7+
<NotFound>
8+
<PageTitle>Not found</PageTitle>
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</NotFound>
11+
</Router>

YAF.SampleApp/Pages/Counter.razor

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/counter"
2+
3+
<PageTitle>Routable Counter</PageTitle>
4+
5+
<h1>Routable Counter</h1>
6+
7+
<p>Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@page
2+
@using YAF.SampleApp.Pages.Shared
3+
@{
4+
ViewData["Title"] = "Blazor Counter on Razor Page";
5+
}
6+
7+
<component type="typeof(Counter)" render-mode="ServerPrerendered" />

YAF.SampleApp/Pages/Index.cshtml

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
}
66

77
<div class="text-center">
8-
<h1>Welcome to ASP.NET and the YAF.NET Sample Application</h1>
9-
<p class="lead">
10-
This Is a Sample Demo Application that shows the Integration of YAF.NET in to an existing ASP.NET Core Application.
11-
</p>
12-
<p> To learn more about YAF.NET visit <a href="http://www.yetanotherforum.net" title="YAF.NET Website">YAF.NET Website</a>.</p>
8+
<h1>Welcome to ASP.NET and the YAF.NET Sample Application</h1>
9+
<p class="lead">
10+
This Is a Sample Demo Application that shows the Integration of YAF.NET in to an existing ASP.NET Core Application.
11+
</p>
12+
<p> To learn more about YAF.NET visit <a href="http://www.yetanotherforum.net" title="YAF.NET Website">YAF.NET Website</a>.</p>
1313
</div>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h1>Counter</h1>
2+
3+
<p>Current count: @currentCount</p>
4+
5+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
6+
7+
@code {
8+
private int currentCount = 0;
9+
10+
private void IncrementCount()
11+
{
12+
currentCount++;
13+
}
14+
}

YAF.SampleApp/Pages/Shared/_Layout.cshtml

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<link href="~/favicons/safari-pinned-tab.svg" rel="mask-icon" color="#5bbad5" />
2222
<link href="~/favicons/favicon.ico" rel="shortcut icon" />
2323
<script src="~/js/themeSelector.min.js"></script>
24+
<base href="~/" />
25+
<component type="typeof(Microsoft.AspNetCore.Components.Web.HeadOutlet)"
26+
render-mode="ServerPrerendered" />
2427
</head>
2528
<body>
2629
<header>
@@ -42,6 +45,12 @@
4245
<li class="nav-item">
4346
<a class="nav-link" asp-area="Chat" asp-page="/Index">Chat</a>
4447
</li>
48+
<li class="nav-item">
49+
<a class="nav-link" href="/Counter">Blazor Counter</a>
50+
</li>
51+
<li class="nav-item">
52+
<a class="nav-link" asp-page="/CounterPage">Blazor Counter on Razor Page</a>
53+
</li>
4554
</ul>
4655
<div class="form-inline mt-2 mt-md-0">
4756
@if (Current.IsGuest)
@@ -81,6 +90,7 @@
8190
{
8291
@await Html.PartialAsync("_LogoutConfirm")
8392
}
93+
<script src="_framework/blazor.server.js"></script>
8494

8595
@await RenderSectionAsync("Scripts", required: false)
8696
</body>

YAF.SampleApp/Pages/_Host.cshtml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@page
2+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3+
4+
<component type="typeof(App)" render-mode="ServerPrerendered" />

YAF.SampleApp/Pages/_Host.cshtml.cs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* Yet Another Forum.NET
2+
* Copyright (C) 2003-2005 Bjørnar Henden
3+
* Copyright (C) 2006-2013 Jaben Cargman
4+
* Copyright (C) 2014-2024 Ingo Herbote
5+
* https://www.yetanotherforum.net/
6+
*
7+
* Licensed to the Apache Software Foundation (ASF) under one
8+
* or more contributor license agreements. See the NOTICE file
9+
* distributed with this work for additional information
10+
* regarding copyright ownership. The ASF licenses this file
11+
* to you under the Apache License, Version 2.0 (the
12+
* "License"); you may not use this file except in compliance
13+
* with the License. You may obtain a copy of the License at
14+
15+
* https://www.apache.org/licenses/LICENSE-2.0
16+
17+
* Unless required by applicable law or agreed to in writing,
18+
* software distributed under the License is distributed on an
19+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20+
* KIND, either express or implied. See the License for the
21+
* specific language governing permissions and limitations
22+
* under the License.
23+
*/
24+
25+
#nullable enable
26+
using Microsoft.AspNetCore.Mvc.RazorPages;
27+
28+
using System.Diagnostics;
29+
30+
using Microsoft.AspNetCore.Mvc;
31+
32+
namespace YAF.SampleApp.Pages;
33+
34+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
35+
[IgnoreAntiforgeryToken]
36+
public class ErrorModel : PageModel
37+
{
38+
public string? RequestId { get; set; }
39+
40+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
41+
42+
public ErrorModel(ILogger<ErrorModel> logger)
43+
{
44+
}
45+
46+
public void OnGet()
47+
{
48+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
49+
}
50+
}

YAF.SampleApp/Pages/_Imports.razor

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@using System.Net.Http
2+
@using Microsoft.AspNetCore.Authorization
3+
@using Microsoft.AspNetCore.Components.Authorization
4+
@using Microsoft.AspNetCore.Components.Forms
5+
@using Microsoft.AspNetCore.Components.Routing
6+
@using Microsoft.AspNetCore.Components.Web
7+
@using Microsoft.AspNetCore.Components.Web.Virtualization
8+
@using Microsoft.JSInterop
9+
@using YAF.SampleApp

YAF.SampleApp/Startup.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,9 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env)
7070
/// <param name="services">The services.</param>
7171
public void ConfigureServices(IServiceCollection services)
7272
{
73-
services.AddRazorPages(options =>
74-
{
75-
options.Conventions.AddPageRoute("/SiteMap", "Sitemap.xml");
76-
}).AddYafRazorPages(this.Environment);
77-
78-
services.AddControllers();
79-
80-
services.AddSignalR();
81-
8273
services.AddYafCore(this.Configuration);
74+
75+
services.AddServerSideBlazor();
8376
}
8477

8578
/// <summary>
@@ -123,7 +116,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
123116
{
124117
endpoints.MapRazorPages();
125118

126-
endpoints.MapAreaControllerRoute(
119+
endpoints.MapBlazorHub();
120+
121+
endpoints.MapFallbackToPage("/_Host");
122+
123+
endpoints.MapAreaControllerRoute(
127124
name: "default",
128125
areaName:"Forums",
129126
pattern: "{controller=Home}/{action=Index}/{id?}");

YAF.SampleApp/YAF.SampleApp.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
1717
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
1818
</Content>
19+
<Content Update="Pages\Counter.razor">
20+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
21+
</Content>
22+
<Content Update="Pages\_Imports.razor">
23+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
24+
</Content>
1925
</ItemGroup>
2026

2127
<ItemGroup>

0 commit comments

Comments
 (0)