From 6cbfe4f7a8866161bd6c00fd9d534a2e4d098d2f Mon Sep 17 00:00:00 2001
From: Marcello Lamonaca
Date: Wed, 10 Aug 2022 17:14:24 +0200
Subject: [PATCH] c# blazor: add nav manager & get/set/after binding modifiers
notes
---
docs/dotnet/asp.net/blazor.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/docs/dotnet/asp.net/blazor.md b/docs/dotnet/asp.net/blazor.md
index 9f5c2d8..85fbaf8 100644
--- a/docs/dotnet/asp.net/blazor.md
+++ b/docs/dotnet/asp.net/blazor.md
@@ -261,6 +261,16 @@ Project
## State Management
+## Passing state with `NavigationManager`
+
+It's now possible to pass state when navigating in Blazor apps using the `NavigationManager`.
+
+```cs
+navigationManager.NavigateTo("/", new NavigationOptions { HistoryEntryState = value });
+```
+
+This mechanism allows for simple communication between different pages. The specified state is pushed onto the browser’s history stack so that it can be accessed later using either the `NavigationManager.HistoryEntryState` property or the `LocationChangedEventArgs.HistoryEntryState` property when listening for location changed events.
+
### Blazor WASM
```cs
@@ -355,6 +365,9 @@ public class StateContainer
// bind to child component {PROPERTY}
// bind to child component {PROPERTY}, listen for custom event
+
+ // run async logic after bind event completion
+ // two-way data binding
@code {
@@ -372,11 +385,17 @@ public class StateContainer
await PropertyChanged.InvokeAsync(e, argument); // notify parent bound prop has changed
await elementReference.FocusAsync(); // focus an element in code
}
+
+ [Parameter] public TValue Value { get; set; }
+ [Parameter] public EventCallback ValueChanged { get; set; }
}
```
**NOTE**: When a user provides an unparsable value to a data-bound element, the unparsable value is automatically reverted to its previous value when the bind event is triggered.
+> **Note**: The `@bind:get` and `@bind:set` modifiers are always used together.
+> `The @bind:get` modifier specifies the value to bind to and the `@bind:set` modifier specifies a callback that is called when the value changes
+
## Javascript/.NET Interop
[Call Javascript from .NET](https://docs.microsoft.com/en-us/aspnet/core/blazor/call-javascript-from-dotnet)