Software Information
Code
This code is a standard
Blazor component that dynamically displays a string on a webpage when the Button is clicked. Here is the breakdown:
Directive
@page: This is the routing directive and it tells Blazor that this component should be loaded when you visit the root URL (the home page) of the application.
@renderMode: Set as Interactive, so that the changes are reflected on the page.
MetaData
PageTitle - This is use to set the Page Title.
HTML Markup
The HTML Markup consists a HTML INPUT Button which has been assigned with a server-side click event handler and below that there is an H1 tag within which the name variable is printed using razor syntax.
@Code Block
The very first thing, is to declare a variable name.
Then inside the Print method, the name variable is initialized and set with a value.
@page "/"
@rendermode InteractiveServer
<PageTitle>Home</PageTitle>
@code {
string? name;
private void Print()
{
name = "Blazor";
}
}
<input type="button" id="btnPrint" value="Print" @onclick = "Print" />
<h1>Hello, world!@name</h1>
Screenshot
Testing Log
Compiled in: Visual Studio 2026
Framework: .Net Core 10.
Result: 100% Success
Downloads