Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page "/todo"

<PageTitle>Todo</PageTitle>

<h1>Todo</h1>

@code {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page "/todo"

<PageTitle>Todo</PageTitle>

<h1>Todo (@todos.Count(todo => !todo.IsDone))</h1>

<ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page "/todo"

<PageTitle>Todo</PageTitle>

<h1>Todo</h1>

<ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page "/todo"

<PageTitle>Todo</PageTitle>

<h1>Todo</h1>

<ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page "/todo"

<PageTitle>Todo</PageTitle>

<h1>Todo</h1>

<ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<ul class="nav flex-column">

...

<li class="nav-item px-3">
<NavLink class="nav-link" href="todo">
<span class="oi oi-list-rich" aria-hidden="true"></span> Todo
</NavLink>
</li>
</ul>
<div class="nav-item px-3">
<NavLink class="nav-link" href="todo">
<span class="oi oi-list-rich" aria-hidden="true"></span> Todo
</NavLink>
</div>
12 changes: 6 additions & 6 deletions aspnetcore/tutorials/build-a-blazor-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ At the end of this tutorial, you'll have a working todo list app.

## Prerequisites

[!INCLUDE[](~/includes/5.0-SDK.md)]
[!INCLUDE[](~/includes/6.0-SDK.md)]

## Create a Blazor app

Expand Down Expand Up @@ -79,11 +79,11 @@ cd TodoList

The `NavMenu` component is used in the app's layout. Layouts are components that allow you to avoid duplication of content in an app. The `NavLink` component provides a cue in the app's UI when the component URL is loaded by the app.

In the unordered list (`<ul>...</ul>`) of the `NavMenu` component, add the following list item (`<li>...</li>`) and `NavLink` component for the `Todo` component.
In the navigation element content (`<nav class="flex-column">`) of the `NavMenu` component, add the following `<div>` element for the `Todo` component.

In `Shared/NavMenu.razor`:

[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Shared/build-a-blazor-app/NavMenu.razor?highlight=5-9)]
[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Shared/build-a-blazor-app/NavMenu.razor)]

Save the `Shared/NavMenu.razor` file.

Expand All @@ -110,11 +110,11 @@ cd TodoList

`Pages/Todo.razor`:

[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/build-a-blazor-app/Todo2.razor?highlight=5-10,13)]
[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/build-a-blazor-app/Todo2.razor?highlight=7-12,15)]

1. The app requires UI elements for adding todo items to the list. Add a text input (`<input>`) and a button (`<button>`) below the unordered list (`<ul>...</ul>`):

[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/build-a-blazor-app/Todo3.razor?highlight=12-13)]
[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/build-a-blazor-app/Todo3.razor?highlight=14-15)]

1. Save the `TodoItem.cs` file and the updated `Pages/Todo.razor` file. In the command shell, the app is automatically rebuilt when the files are saved. The browser reloads the page.

Expand All @@ -136,7 +136,7 @@ cd TodoList

1. Update the `AddTodo` method to add the `TodoItem` with the specified title to the list. Clear the value of the text input by setting `newTodo` to an empty string:

[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/build-a-blazor-app/Todo6.razor?highlight=19-26)]
[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/build-a-blazor-app/Todo6.razor?highlight=21-28)]

1. Save the `Pages/Todo.razor` file. The app is automatically rebuilt in the command shell, and the page reloads in the browser.

Expand Down
36 changes: 18 additions & 18 deletions aspnetcore/tutorials/signalr-blazor.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ At the end of this tutorial, you'll have a working chat app.

# [Visual Studio](#tab/visual-studio)

* [Visual Studio 2019 16.10 or later](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019) with the **ASP.NET and web development** workload
* [!INCLUDE [.NET Core 5.0 SDK](~/includes/5.0-SDK.md)]
* [Visual Studio 2022 or later](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2022) with the **ASP.NET and web development** workload
* [!INCLUDE [.NET Core 6.0 SDK](~/includes/6.0-SDK.md)]

# [Visual Studio Code](#tab/visual-studio-code)

[!INCLUDE[](~/includes/net-core-prereqs-vsc-5.0.md)]
[!INCLUDE[](~/includes/net-prereqs-vsc-6.0.md)]

# [Visual Studio for Mac](#tab/visual-studio-mac)

* [Visual Studio for Mac version 8.8 or later](https://visualstudio.microsoft.com/vs/mac/)
* [!INCLUDE [.NET Core 5.0 SDK](~/includes/5.0-SDK.md)]
* [Visual Studio for Mac 2022 or later](https://visualstudio.microsoft.com/vs/mac/)
* [!INCLUDE [.NET Core 6.0 SDK](~/includes/6.0-SDK.md)]

# [.NET Core CLI](#tab/netcore-cli/)

[!INCLUDE[](~/includes/5.0-SDK.md)]
[!INCLUDE[](~/includes/6.0-SDK.md)]

---

Expand All @@ -58,7 +58,7 @@ Follow the guidance for your choice of tooling:
# [Visual Studio](#tab/visual-studio)

> [!NOTE]
> Visual Studio 16.10 or later and .NET Core SDK 5.0.0 or later are required.
> Visual Studio 2022 or later and .NET Core SDK 6.0.0 or later are required.

1. Create a new project.

Expand Down Expand Up @@ -179,24 +179,24 @@ In the `BlazorWebAssemblySignalRApp.Server` project, create a `Hubs` (plural) fo

## Add services and an endpoint for the SignalR hub

1. In the `BlazorWebAssemblySignalRApp.Server` project, open the `Startup.cs` file.
1. In the `BlazorWebAssemblySignalRApp.Server` project, open the `Program.cs` file.

1. Add the namespace for the `ChatHub` class to the top of the file:

```csharp
using BlazorWebAssemblySignalRApp.Server.Hubs;
```

1. Add SignalR and Response Compression Middleware services to `Startup.ConfigureServices`:
1. Add SignalR and Response Compression Middleware services to `Program.cs`:

[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorWebAssemblySignalRApp/Server/Startup.cs?name=snippet_ConfigureServices&highlight=3,6-10)]
[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorWebAssemblySignalRApp/Server/Program.cs?name=snippet_ConfigureServices)]

1. In `Startup.Configure`:
1. In `Program.cs`:

* Use Response Compression Middleware at the top of the processing pipeline's configuration.
* Between the endpoints for controllers and the client-side fallback, add an endpoint for the hub.

[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorWebAssemblySignalRApp/Server/Startup.cs?name=snippet_Configure&highlight=3,26)]
[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorWebAssemblySignalRApp/Server/Program.cs?name=snippet_Configure)]

## Add Razor component code for chat

Expand Down Expand Up @@ -278,7 +278,7 @@ Follow the guidance for your choice of tooling:
# [Visual Studio](#tab/visual-studio)

> [!NOTE]
> Visual Studio 16.10 or later and .NET Core SDK 5.0.0 or later are required.
> Visual Studio 2022 or later and .NET Core SDK 6.0.0 or later are required.

1. Create a new project.

Expand Down Expand Up @@ -390,7 +390,7 @@ Create a `Hubs` (plural) folder and add the following `ChatHub` class (`Hubs/Cha

## Add services and an endpoint for the SignalR hub

1. Open the `Startup.cs` file.
1. Open the `Program.cs` file.

1. Add the namespaces for <xref:Microsoft.AspNetCore.ResponseCompression?displayProperty=fullName> and the `ChatHub` class to the top of the file:

Expand All @@ -399,16 +399,16 @@ Create a `Hubs` (plural) folder and add the following `ChatHub` class (`Hubs/Cha
using BlazorServerSignalRApp.Server.Hubs;
```

1. Add Response Compression Middleware services to `Startup.ConfigureServices`:
1. Add Response Compression Middleware services to `Program.cs`:

[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorServerSignalRApp/Startup.cs?name=snippet_ConfigureServices&highlight=6-10)]
[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorServerSignalRApp/Program.cs?name=snippet_ConfigureServices)]

1. In `Startup.Configure`:
1. In `Program.cs`:

* Use Response Compression Middleware at the top of the processing pipeline's configuration.
* Between the endpoints for mapping the Blazor hub and the client-side fallback, add an endpoint for the hub.

[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorServerSignalRApp/Startup.cs?name=snippet_Configure&highlight=3,23)]
[!code-csharp[](~/tutorials/signalr-blazor/samples/6.0/BlazorServerSignalRApp/Program.cs?name=snippet_Configure)]

## Add Razor component code for chat

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.0-rc.1.21452.15" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
namespace BlazorServerSignalRApp.Data;

namespace BlazorServerSignalRApp.Data
public class WeatherForecast
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public DateTime Date { get; set; }

public int TemperatureC { get; set; }
public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
public string? Summary { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
using System;
using System.Linq;
using System.Threading.Tasks;
namespace BlazorServerSignalRApp.Data;

namespace BlazorServerSignalRApp.Data
public class WeatherForecastService
{
public class WeatherForecastService
private static readonly string[] Summaries = new[]
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
var rng = new Random();
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
}).ToArray());
}
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@page "/counter"
@page "/counter"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p>Current count: @currentCount</p>
<p role="status">Current count: @currentCount</p>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/app.css" rel="stylesheet" />
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
</head>

<body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;

namespace BlazorServerSignalRApp.Pages
namespace BlazorServerSignalRApp.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;
private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page "/fetchdata"

<PageTitle>Weather forecast</PageTitle>

@using BlazorServerSignalRApp.Data
@inject WeatherForecastService ForecastService

Expand Down Expand Up @@ -37,7 +39,7 @@ else
}

@code {
private WeatherForecast[] forecasts;
private WeatherForecast[]? forecasts;

protected override async Task OnInitializedAsync()
{
Expand Down
Loading