Blazor Components

@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++;}}

1) Partial File approach:

@page “/counter”<h1>Counter</h1><p>Current count: @currentCount</p><button class=”btn btn-primary” @onclick=”IncrementCount”>Click me</button>
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;namespace TestApp.Pages{public partial class Counter{private int currentCount = 0;private void IncrementCount(){currentCount++;}}}

2) Base Class

@page “/counter”@inherits CounterBase<h1>Counter</h1><p>Current count: @currentCount</p><button class=”btn btn-primary” @onclick=”IncrementCount”>Click me</button>
using Microsoft.AspNetCore.Components;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;namespace TestApp.Pages{public class CounterBase:ComponentBase{protected int currentCount = 0;protected void IncrementCount(){currentCount++;}}}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store