Connecting to the assistant...
} else { ... } ``` Disable a button until a component is interactive: ```razor ``` Disable a form during prerendering and enable the form when the component is interactive: ```razor@Greeting
@message@ChildContent
@code { private string message = "Not updated yet."; [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public string Greeting { get; set; } = "Hello!"; private void UpdateMessage() { message = "Somebody updated me!"; } } ``` ### Render mode inheritance If the `SharedMessage` component is placed in a statically-rendered parent component, the `SharedMessage` component is also rendered statically and isn't interactive. The button doesn't call `UpdateMessage`, and the message isn't updated. `RenderMode5.razor`: ```razor @page "/render-mode-5"Loading...
} else { @Body } @code { [CascadingParameter] private HttpContext? HttpContext { get; set; } protected override void OnParametersSet() { if (HttpContext is null) { Navigation.Refresh(forceReload: true); } } } ``` > [!NOTE] > In the Blazor Web App project template, there's a second layout file (`ManageLayout.razor` in the `Components/Account/Shared` folder) for Identity components in the `Components/Account/Pages/Manage` folder. The `Manage` folder has its own `_Imports.razor` file to apply to the `ManageLayout` to components in the folder. In your own apps, using nested `_Imports.razor` files is a useful approach for applying custom layouts to groups of pages. In the `App` component, any request for a component in the `Account` folder applies a `null` render mode, which enforces static SSR. Other component requests receive a global application of the interactive SSR render mode (`InteractiveServer`). > [!IMPORTANT] > Applying a `null` render mode doesn't always enforce static SSR. It just happens to behave that way using the approach shown in this section. > > A `null` render mode is effectively the same as not specifying a render mode, which results in the component inheriting its parent's render mode. In this case, the `App` component is rendered using static SSR, so a `null` render mode results in the `Routes` component inheriting static SSR from the `App` component. If a null render mode is specified for a child component whose parent uses an interactive render mode, the child inherits the same interactive render mode. `Components/App.razor`: ```razorLoading...
} else { @Body } @code { [CascadingParameter] private HttpContext? HttpContext { get; set; } protected override void OnParametersSet() { if (HttpContext is null) { Navigation.Refresh(forceReload: true); } } } ``` In the `App` component, reflection is used to set the render mode. Whatever render mode is assigned to the individual component definition file is applied to the `Routes` component. `Components/App.razor`: ```razorEnvironment: @Environment.Environment
``` No compile time error occurs, but a runtime error occurs during prerendering: > :::no-loc text="Cannot provide a value for property 'Environment' on type 'BlazorSample.Client.Pages.Home'. There is no registered service of type 'Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment'."::: This error occurs because the component must compile and execute on the server during prerendering, butEnvironment: @environmentName
@code { private string? environmentName; protected override void OnInitialized() { if (Services.GetService