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
18 changes: 9 additions & 9 deletions aspnetcore/blazor/call-web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Use the following `TodoItem` class with this article's examples if you build the
public class TodoItem
{
public long Id { get; set; }
public string Name { get; set; }
public string? Name { get; set; }
public bool IsComplete { get; set; }
}
```
Expand Down Expand Up @@ -109,7 +109,7 @@ else
}

@code {
private TodoItem[] todoItems;
private TodoItem[]? todoItems;

protected override async Task OnInitializedAsync() =>
todoItems = await Http.GetFromJsonAsync<TodoItem[]>("api/TodoItems");
Expand All @@ -132,7 +132,7 @@ In the following component code, `newItemName` is provided by a bound element of
<button @onclick="AddItem">Add</button>

@code {
private string newItemName;
private string? newItemName;

private async Task AddItem()
{
Expand All @@ -152,7 +152,7 @@ var content = await response.Content.ReadFromJsonAsync<WeatherForecast>();

<xref:System.Net.Http.Json.HttpClientJsonExtensions.PutAsJsonAsync%2A> sends an HTTP PUT request with JSON-encoded content.

In the following component code, `editItem` values for `Name` and `IsCompleted` are provided by bound elements of the component. The item's `Id` is set when the item is selected in another part of the UI (not shown) and `EditItem` is called. The `SaveItem` method is triggered by selecting the `<button>` element.
In the following component code, `editItem` values for `Name` and `IsCompleted` are provided by bound elements of the component. The item's `Id` is set when the item is selected in another part of the UI (not shown) and `EditItem` is called. The `SaveItem` method is triggered by selecting the `<button>` element. Note that the following example doesn't show loading `todoItems` for brevity (see the [GET from JSON (`GetFromJsonAsync`)](#get-from-json-getfromjsonasync) section for an example of loading items).

```razor
@using System.Net.Http
Expand All @@ -165,7 +165,7 @@ In the following component code, `editItem` values for `Name` and `IsCompleted`
<button @onclick="SaveItem">Save</button>

@code {
private string id;
private string? id;
private TodoItem editItem = new TodoItem();

private void EditItem(long id)
Expand Down Expand Up @@ -258,7 +258,7 @@ else
}

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

protected override async Task OnInitializedAsync()
{
Expand Down Expand Up @@ -351,7 +351,7 @@ else
}

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

protected override async Task OnInitializedAsync()
{
Expand Down Expand Up @@ -456,8 +456,8 @@ else
</p>

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

protected override async Task OnInitializedAsync()
{
Expand Down
32 changes: 14 additions & 18 deletions aspnetcore/blazor/components/cascading-values-and-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,22 @@ In the following example, two [`CascadingValue`](xref:Microsoft.AspNetCore.Compo
</CascadingValue>

@code {
private CascadingType parentCascadeParameter1;
private CascadingType? parentCascadeParameter1;

[Parameter]
public CascadingType ParentCascadeParameter2 { get; set; }

...
public CascadingType? ParentCascadeParameter2 { get; set; }
}
```

In a descendant component, the cascaded parameters receive their cascaded values from the ancestor component by <xref:Microsoft.AspNetCore.Components.CascadingValue%601.Name%2A>:

```razor
...

@code {
[CascadingParameter(Name = "CascadeParam1")]
protected CascadingType ChildCascadeParameter1 { get; set; }
protected CascadingType? ChildCascadeParameter1 { get; set; }

[CascadingParameter(Name = "CascadeParam2")]
protected CascadingType ChildCascadeParameter2 { get; set; }
protected CascadingType? ChildCascadeParameter2 { get; set; }
}
```

Expand Down Expand Up @@ -131,13 +127,13 @@ Child `Tab` components aren't explicitly passed as parameters to the `TabSet`. I

@code {
[Parameter]
public RenderFragment ChildContent { get; set; }
public RenderFragment? ChildContent { get; set; }

public ITab ActiveTab { get; private set; }
public ITab? ActiveTab { get; private set; }

public void AddTab(ITab tab)
{
if (ActiveTab == null)
if (ActiveTab is null)
{
SetActiveTab(tab);
}
Expand Down Expand Up @@ -170,25 +166,25 @@ Descendent `Tab` components capture the containing `TabSet` as a cascading param

@code {
[CascadingParameter]
public TabSet ContainerTabSet { get; set; }
public TabSet? ContainerTabSet { get; set; }

[Parameter]
public string Title { get; set; }
public string? Title { get; set; }

[Parameter]
public RenderFragment ChildContent { get; set; }
public RenderFragment? ChildContent { get; set; }

private string TitleCssClass =>
ContainerTabSet.ActiveTab == this ? "active" : null;
private string? TitleCssClass =>
ContainerTabSet?.ActiveTab == this ? "active" : null;

protected override void OnInitialized()
{
ContainerTabSet.AddTab(this);
ContainerTabSet?.AddTab(this);
}

private void ActivateTab()
{
ContainerTabSet.SetActiveTab(this);
ContainerTabSet?.SetActiveTab(this);
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/class-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ Blazor WebAssembly and RCL projects *automatically* enable browser compatibility
When authoring a library, indicate that a particular API isn't supported in browsers by specifying `browser` to <xref:System.Runtime.Versioning.UnsupportedOSPlatformAttribute>:

```csharp
using System.Runtime.Versioning;

...

[UnsupportedOSPlatform("browser")]
private static string GetLoggingDirectory()
{
Expand Down
25 changes: 1 addition & 24 deletions aspnetcore/blazor/components/control-head-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,7 @@ The following example sets the page's title and description using Razor.

`Pages/ControlHeadContent.razor`:

```razor
@page "/control-head-content"

<h1>Control &lt;head&gt; content</h1>

<p>
Title: @title
</p>

<p>
Description: @description
</p>

<PageTitle>@title</PageTitle>

<HeadContent>
<meta name="description" content="@description">
</HeadContent>

@code {
private string description = "Description set by component";
private string title = "Title set by component";
}
```
[!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/control-head-content/ControlHeadContent.razor?highlight=13,15-17)]

## Control head content during prerendering

Expand Down
5 changes: 4 additions & 1 deletion aspnetcore/blazor/components/data-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ Binding supports [`multiple`](https://developer.mozilla.org/docs/Web/HTML/Attrib

void SelectedCarsChanged(ChangeEventArgs e)
{
SelectedCars = (string[])e.Value;
if (e.Value is not null)
{
SelectedCars = (string[])e.Value;
}
}
}
```
Expand Down
Loading