Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blazor Code-behind
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
public partial class Counter
{
...
}
public partial class Counter
{
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
public class CounterBase : ComponentBase
{
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
@page "/counter"
@inherits CounterBase
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
public class CounterBase : ComponentBase
{
protected int CurrentCount { get; set; } = 0;
protected void IncrementCount()
{
this.CurrentCount++;
}
}
public class CounterBase : ComponentBase
{
protected int CurrentCount { get; set; } = 0;
protected void IncrementCount()
{
this.CurrentCount++;
}
protected override async Task OnInitializedAsync()
{
this.CurrentCount = 10;
}
}
@page "/counter"
@inherits CounterBase
<h1>Counter</h1>
<p>Current count: @CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
public partial class Counter : ComponentBase
{
protected int CurrentCount { get; set; } = 0;
protected void IncrementCount()
{
this.CurrentCount++;
}
protected override async Task OnInitializedAsync()
{
this.CurrentCount = 10;
}
}
@page "/counter"
<h1>Counter</h1>
<p>Current count: @CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment