Hi @打玻璃
and use in it razor pages as static
<component type="typeof(Components.Counter)" render-mode="Static" param-start="10"/>how to refresh it partialy not refresh the page?
To solve this issue, you need to Change the Render Mode from Static to ServerPrerendered: because when using the static mode, it will render the component into static HTML.
Based on your description, I create a sample use the following code, you can refer to it:
In the Program.cs file, add the MapBlazorHub middleware and AddServerSideBlazor service:
builder.Services.AddServerSideBlazor();
app.MapBlazorHub();
In the _Layout.cshtml page, add the _framework/blazor.server.js script reference:
In the Counter component, add the Microsoft.AspNetCore.Components and Microsoft.AspNetCore.Components.Web reference:
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Web
<h1>@Title</h1>
<p role="status">Current count: @currentCount</p>
<p>Increment amount: @IncrementAmount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
[Parameter] public string Title { get; set; } = "Blazor Counter";
[Parameter] public int? IncrementAmount { get; set; }
private void IncrementCount()
{
currentCount += IncrementAmount.GetValueOrDefault(1);
}
}
In the Razor page, use the following code to display the component:
<component type="typeof(Components.Counter)" render-mode="ServerPrerendered" param-IncrementAmount="2" />
The result as below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion