Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` **Razor Pages**: In the project's `Index` page of a Razor Pages app, add the `Counter` component's namespace and embed the component into the page. When the `Index` page loads, the `Counter` component is prerendered in the page. In the following example, replace the `{APP NAMESPACE}` placeholder with the project's namespace. `Pages/Index.cshtml`: ```cshtml @page @using {APP NAMESPACE}.Pages.Shared @model IndexModel @{ ViewData["Title"] = "Home page"; }Sorry, there's nothing at this address.
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Use routable components in an MVC app *This section pertains to adding components that are directly routable from user requests.* To support routable Razor components in MVC apps: 1. Follow the guidance in the [Configuration](#configuration) section. 1. Add an `App` component to the project root with the following content. `App.razor`: ```razor @using Microsoft.AspNetCore.Components.RoutingSorry, there's nothing at this address.
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Render components from a page or view *This section pertains to adding components to pages or views, where the components aren't directly routable from user requests.* To render a component from a page or view, use the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper). ### Render stateful interactive components Stateful interactive components can be added to a Razor page or view. When the page or view renders: * The component is prerendered with the page or view. * The initial component state used for prerendering is lost. * New component state is created when the SignalR connection is established. The following Razor page renders a `Counter` component: ```cshtmlThis component demonstrates fetching data from the server.
@if (forecasts == null) {Loading...
} else {Date | Temp. (C) | Temp. (F) | Summary |
---|---|---|---|
@forecast.Date.ToShortDateString() | @forecast.TemperatureC | @forecast.TemperatureF | @forecast.Summary |
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` **Razor Pages**: In the project's `Index` page of a Razor Pages app, add the `Counter` component's namespace and embed the component into the page. When the `Index` page loads, the `Counter` component is prerendered in the page. In the following example, replace the `{APP NAMESPACE}` placeholder with the project's namespace. `Pages/Index.cshtml`: ```cshtml @page @using {APP NAMESPACE}.Pages.Shared @model IndexModel @{ ViewData["Title"] = "Home page"; }Sorry, there's nothing at this address.
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Use routable components in an MVC app *This section pertains to adding components that are directly routable from user requests.* To support routable Razor components in MVC apps: 1. Follow the guidance in the [Configuration](#configuration) section. 1. Add an `App` component to the project root with the following content. `App.razor`: ```razor @using Microsoft.AspNetCore.Components.RoutingSorry, there's nothing at this address.
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Render components from a page or view *This section pertains to adding components to pages or views, where the components aren't directly routable from user requests.* To render a component from a page or view, use the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper). ### Render stateful interactive components Stateful interactive components can be added to a Razor page or view. When the page or view renders: * The component is prerendered with the page or view. * The initial component state used for prerendering is lost. * New component state is created when the SignalR connection is established. The following Razor page renders a `Counter` component: ```cshtmlThis component demonstrates fetching data from the server.
@if (forecasts == null) {Loading...
} else {Date | Temp. (C) | Temp. (F) | Summary |
---|---|---|---|
@forecast.Date.ToShortDateString() | @forecast.TemperatureC | @forecast.TemperatureF | @forecast.Summary |
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` **Razor Pages**: In the project's `Index` page of a Razor Pages app, add the `Counter` component's namespace and embed the component into the page. When the `Index` page loads, the `Counter` component is prerendered in the page. In the following example, replace the `{APP NAMESPACE}` placeholder with the project's namespace. `Pages/Index.cshtml`: ```cshtml @page @using {APP NAMESPACE}.Pages.Shared @model IndexModel @{ ViewData["Title"] = "Home page"; }Sorry, but there's nothing here!
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Use routable components in an MVC app *This section pertains to adding components that are directly routable from user requests.* To support routable Razor components in MVC apps: 1. Follow the guidance in the [Configuration](#configuration) section. 1. Add an `App` component to the project root with the following content. `App.razor`: ```razor @using Microsoft.AspNetCore.Components.RoutingSorry, but there's nothing here!
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Render components from a page or view *This section pertains to adding components to pages or views, where the components aren't directly routable from user requests.* To render a component from a page or view, use the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper). ### Render stateful interactive components Stateful interactive components can be added to a Razor page or view. When the page or view renders: * The component is prerendered with the page or view. * The initial component state used for prerendering is lost. * New component state is created when the SignalR connection is established. The following Razor page renders a `Counter` component: ```cshtmlCurrent count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` **Razor Pages**: In the project's `Index` page of a Razor Pages app, add the `Counter` component's namespace and embed the component into the page. When the `Index` page loads, the `Counter` component is prerendered in the page. In the following example, replace the `{APP NAMESPACE}` placeholder with the project's namespace. `Pages/Index.cshtml`: ```cshtml @page @using {APP NAMESPACE}.Pages.Shared @model IndexModel @{ ViewData["Title"] = "Home page"; }Sorry, but there's nothing here!
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Use routable components in an MVC app *This section pertains to adding components that are directly routable from user requests.* To support routable Razor components in MVC apps: 1. Follow the guidance in the [Configuration](#configuration) section. 1. Add an `App` component to the project root with the following content. `App.razor`: ```razor @using Microsoft.AspNetCore.Components.RoutingSorry, but there's nothing here!
Current count: @currentCount
@code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } ``` 1. Run the project and navigate to the routable `RoutableCounter` component at `/routable-counter`. For more information on namespaces, see the [Component namespaces](#component-namespaces) section. ## Render components from a page or view *This section pertains to adding components to pages or views, where the components aren't directly routable from user requests.* To render a component from a page or view, use the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper). ### Render stateful interactive components Stateful interactive components can be added to a Razor page or view. When the page or view renders: * The component is prerendered with the page or view. * The initial component state used for prerendering is lost. * New component state is created when the SignalR connection is established. The following Razor page renders a `Counter` component: ```cshtml