Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created March 7, 2021 22:37
Show Gist options
  • Save justinyoo/adf1539f817c4b604c5cedc421e96aed to your computer and use it in GitHub Desktop.
Save justinyoo/adf1539f817c4b604c5cedc421e96aed to your computer and use it in GitHub Desktop.
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