Skip to content

Update blazor example to .NET 8 Blazor templates #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
412 changes: 412 additions & 0 deletions examples/blazor/.gitignore

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions examples/blazor/Nutrient-BlazorServer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36221.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nutrient-BlazorServer", "Nutrient-BlazorServer\Nutrient-BlazorServer.csproj", "{9A460DB3-FFA5-4DBE-B535-66882696BAAF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nutrient-BlazorWASM", "Nutrient-BlazorWASM\Nutrient-BlazorWASM\Nutrient-BlazorWASM.csproj", "{1BCB3380-02EF-4586-B3E8-7C701EBAC858}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nutrient-BlazorWASM.Client", "Nutrient-BlazorWASM\Nutrient-BlazorWASM.Client\Nutrient-BlazorWASM.Client.csproj", "{F3111550-3A64-426B-8C39-FB32334BF4C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Release|Any CPU.Build.0 = Release|Any CPU
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Release|Any CPU.Build.0 = Release|Any CPU
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3DA9C8F6-0D45-466D-A92B-06663484C192}
EndGlobalSection
EndGlobal
30 changes: 30 additions & 0 deletions examples/blazor/Nutrient-BlazorServer/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="Nutrient-BlazorServer.styles.css" />
<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
@* Include nutrient-viewer.js in your Pages/_Host.cshtml file *@
<script src=nutrient-viewer.js"></script>
@* Initialize Nutrient Viewer in Blazor Server by calling NutrientViewer.load(): *@
<script>
function loadPDF(container, document) {
NutrientViewer.load({
container: container,
document: document
})
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@inherits LayoutComponentBase

@Body

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}

#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
36 changes: 36 additions & 0 deletions examples/blazor/Nutrient-BlazorServer/Components/Pages/Error.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics

<PageTitle>Error</PageTitle>

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }

private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
@page "/"
@inject IJSRuntime JS

<div id='container' style='background: gray; width: 100vw; height: 100vh; margin: 0 auto;'></div>

@code {

protected override async void OnAfterRender(bool firstRender)
{
if (firstRender) {
await JS.InvokeVoidAsync("loadPDF", "#container", "document.pdf");
}
}
}
@page "/"
@rendermode InteractiveServer
@inject IJSRuntime JS

<div id='container' style='background: gray; width: 100vw; height: 100vh; margin: 0 auto;'></div>

@code {

protected override async void OnAfterRender(bool firstRender)
{
if (firstRender)
{
await JS.InvokeVoidAsync("loadPDF", "#container", "document.pdf");
}
}
}
6 changes: 6 additions & 0 deletions examples/blazor/Nutrient-BlazorServer/Components/Routes.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Nutrient_BlazorServer
@using Nutrient_BlazorServer.Shared
@using Nutrient_BlazorServer.Components
11 changes: 11 additions & 0 deletions examples/blazor/Nutrient-BlazorServer/Nutrient-BlazorServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Nutrient-BlazorServer</RootNamespace>
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>
</PropertyGroup>

</Project>
36 changes: 36 additions & 0 deletions examples/blazor/Nutrient-BlazorServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.StaticFiles;
using Nutrient_BlazorServer.Components;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

FileExtensionContentTypeProvider extensionProvider = new();
extensionProvider.Mappings.Add(".dll", "application/octet-stream");
extensionProvider.Mappings.Add(".dat", "application/octet-stream");
extensionProvider.Mappings.Add(".blat", "application/octet-stream");

app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = extensionProvider
});
app.UseAntiforgery();

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

app.Run();
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:48174",
"sslPort": 44361
"applicationUrl": "http://localhost:5480",
"sslPort": 44348
}
},
"profiles": {
"nutrient-blazor-server": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7166;http://localhost:5133",
"applicationUrl": "http://localhost:5025",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7237;http://localhost:5025",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,17 @@
@import url("open-iconic/font/css/open-iconic-bootstrap.min.css");

html,
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

h1:focus {
outline: none;
}

a,
.btn-link {
color: #0071c1;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.content {
padding-top: 1.1rem;
}

.valid.modified:not([type="checkbox"]) {
outline: 1px solid #26b050;
}

.invalid {
outline: 1px solid red;
outline: 1px solid #e50000;
}

.validation-message {
color: red;
}

#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}

#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
color: #e50000;
}

.blazor-error-boundary {
Expand All @@ -65,3 +24,7 @@ a,
.blazor-error-boundary::after {
content: "An error has occurred.";
}

.darker-border-checkbox.form-check-input {
border-color: #929292;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
<RootNamespace>Nutrient-BlazorWASM.Client</RootNamespace>
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.17" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using Nutrient_BlazorWASM
@using Nutrient_BlazorWASM.Shared
@using Nutrient_BlazorWASM.Client
Loading
Loading