[Blazor] Calling .NET from JS - explanation of scenarios for DotNetObjectReference and instance methods (#33910)
parent
4a78bf35df
commit
433b86e8e6
|
@ -1169,14 +1169,14 @@ In the preceding example:
|
|||
|
||||
## Component instance .NET method helper class
|
||||
|
||||
A helper class can invoke a .NET instance method as an <xref:System.Action>. Helper classes are useful in the following scenarios:
|
||||
A helper class can invoke a .NET instance method as an <xref:System.Action>. Helper classes are useful in scenarios where using static .NET methods aren't applicable:
|
||||
|
||||
* When several components of the same type are rendered on the same page.
|
||||
* In server-side apps with multiple users concurrently using the same component.
|
||||
|
||||
In the following example:
|
||||
|
||||
* The component contains several `ListItem1` components, which is a shared component in the app's `Shared` folder.
|
||||
* The component contains several `ListItem1` components.
|
||||
* Each `ListItem1` component is composed of a message and a button.
|
||||
* When a `ListItem1` component button is selected, that `ListItem1`'s `UpdateMessage` method changes the list item text and hides the button.
|
||||
|
||||
|
@ -1345,7 +1345,7 @@ The assignment of a <xref:Microsoft.JSInterop.DotNetObjectReference> to a proper
|
|||
* In the component's [`OnAfterRender{Async}` method](xref:blazor/components/lifecycle#after-component-render-onafterrenderasync), a JavaScript (JS) function is invoked with the element reference and the component instance as a <xref:Microsoft.JSInterop.DotNetObjectReference>. The JS function attaches the <xref:Microsoft.JSInterop.DotNetObjectReference> to the element in a property.
|
||||
* When an element event is invoked in JS (for example, `onclick`), the element's attached <xref:Microsoft.JSInterop.DotNetObjectReference> is used to call a .NET method.
|
||||
|
||||
Similar to the approach described in the [Component instance .NET method helper class](#component-instance-net-method-helper-class) section, this approach is useful in the following scenarios:
|
||||
Similar to the approach described in the [Component instance .NET method helper class](#component-instance-net-method-helper-class) section, this approach is useful in scenarios where using static .NET methods aren't applicable:
|
||||
|
||||
* When several components of the same type are rendered on the same page.
|
||||
* In server-side apps with multiple users concurrently using the same component.
|
||||
|
|
Loading…
Reference in New Issue