Skip to content

Commit

Permalink
#9 Added further Blazor support
Browse files Browse the repository at this point in the history
  • Loading branch information
Eiler Poulsen committed Mar 5, 2023
1 parent 1f01602 commit 3f29c7c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ Open the App Service running your service on the Azure Portal. Under Settings pr
The same steps are described here:

https://github.com/Azure/app-service-linux-docs/blob/master/Runtime_Support/dot_net_core.md#how-to-update-your-app-to-target-a-different-version-of-net-or-net-core

## Added Blazor support for ASP.NET Razor Pages

The process of adding Blazor support is based on the following article: https://mikaelkoskinen.net/post/combining-razor-blazor-pages-single-asp-net-core-3-application.

The project was initially created using Razor Pages template. Blazor support has been added manually. See https://github.com/Microhive/WebApp/issues/9.
11 changes: 11 additions & 0 deletions WebApp/Pages/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@using Microsoft.AspNetCore.Components.Routing

<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" />
</Found>
<NotFound>
<h1>Page not found</h1>
<p>Sorry, but there's nothing here!</p>
</NotFound>
</Router>
16 changes: 16 additions & 0 deletions WebApp/Pages/Privacy/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@page "/Privacy/Counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
int currentCount = 0;

void IncrementCount()
{
currentCount++;
}
}
4 changes: 4 additions & 0 deletions WebApp/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/WebApp.styles.css" asp-append-version="true" />
<base href="~/" />
</head>
<body>
<header>
Expand All @@ -28,6 +29,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="/Counter">Blazor Counter</a>
</li>
</ul>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions WebApp/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page "/blazor"

@{
Layout = "_Layout";
}

<app>
@(await Html.RenderComponentAsync<App>(RenderMode.Server))
</app>
1 change: 1 addition & 0 deletions WebApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@

app.MapRazorPages();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();
6 changes: 6 additions & 0 deletions WebApp/WebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
</ItemGroup>

<ItemGroup>
<None Remove="Pages\Privacy\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Pages\Privacy\" />
</ItemGroup>
</Project>

0 comments on commit 3f29c7c

Please sign in to comment.