Activate InteractiveServer rendermode to whole app, add and use Blazor.Storage package, display current render mode, remove added stuff that was required for static rendering

This commit is contained in:
2026-02-06 22:14:45 +01:00
parent 0878d0885a
commit 88e02c27ee
5 changed files with 43 additions and 3 deletions

View File

@@ -15,7 +15,7 @@
</head> </head>
<body> <body>
<Routes /> <Routes @rendermode="InteractiveServer" />
<ReconnectModal /> <ReconnectModal />
<script src="@Assets["_framework/blazor.web.js"]"></script> <script src="@Assets["_framework/blazor.web.js"]"></script>
</body> </body>

View File

@@ -1,11 +1,13 @@
@page "/register" @page "/register"
@using Blazored.LocalStorage
@using Sandbox.Models.ViewModels @using Sandbox.Models.ViewModels
@inject Sandbox.App.Services.AuthService.IAuthService AuthService @inject Sandbox.App.Services.AuthService.IAuthService AuthService
@inject ILocalStorageService LocalStorageService
<title>Register</title> <title>Register</title>
<EditForm Model="user" OnValidSubmit="HandleRegistration" OnInvalidSubmit="HandleInvalidSubmit" FormName="registerForm"> <EditForm Model="user" OnValidSubmit="HandleRegistration" OnInvalidSubmit="HandleInvalidSubmit">
<DataAnnotationsValidator/> <DataAnnotationsValidator/>
<div class="d-flex justify-content-center align-items-center"> <div class="d-flex justify-content-center align-items-center">
<div class="col-md-4 p-5 shadow-sm border rounded-3"> <div class="col-md-4 p-5 shadow-sm border rounded-3">
@@ -39,6 +41,10 @@
</div> </div>
</EditForm> </EditForm>
<div class="text-info">
@RendererInfo.Name
</div>
<div class="text-danger"> <div class="text-danger">
<span>@errorMessage</span> <span>@errorMessage</span>
</div> </div>
@@ -48,7 +54,7 @@
</div> </div>
@code { @code {
[SupplyParameterFromForm] private UserRegister user { get; set; } private UserRegister user { get; set; }
private string message = string.Empty; private string message = string.Empty;
private string messageCssClass = string.Empty; private string messageCssClass = string.Empty;
@@ -61,6 +67,8 @@
var result = await AuthService.Register(user); var result = await AuthService.Register(user);
message = result.Message; message = result.Message;
messageCssClass = result.Success ? "text-success" : "text-danger"; messageCssClass = result.Success ? "text-success" : "text-danger";
await LocalStorageService.SetItemAsync("test", message);
} }
async Task HandleInvalidSubmit() async Task HandleInvalidSubmit()

View File

@@ -1,3 +1,4 @@
using Blazored.LocalStorage;
using Sandbox; using Sandbox;
using Sandbox.Components; using Sandbox.Components;
using Sandbox.Models.ViewModels; using Sandbox.Models.ViewModels;
@@ -10,6 +11,9 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents() builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(); .AddInteractiveServerComponents();
// Blazor.Storage
builder.Services.AddBlazoredLocalStorage();
// Blazor client services // Blazor client services
builder.Services.AddScoped<ClientServices.AuthService.IAuthService, ClientServices.AuthService.AuthService>(); builder.Services.AddScoped<ClientServices.AuthService.IAuthService, ClientServices.AuthService.AuthService>();

View File

@@ -9,4 +9,8 @@
<BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException> <BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazor.Storage" Version="5.0.0" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "blazor-server-mini-sandbox", "blazor-server-mini-sandbox.csproj", "{A4595977-F945-77FD-CAC9-1B945F061E97}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A4595977-F945-77FD-CAC9-1B945F061E97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4595977-F945-77FD-CAC9-1B945F061E97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4595977-F945-77FD-CAC9-1B945F061E97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4595977-F945-77FD-CAC9-1B945F061E97}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08319A16-FD23-406A-9429-7EA3AFE8A9DD}
EndGlobalSection
EndGlobal