Blazor vs JavaScript Sample Code 01

Published on Tuesday, May 7, 2019

The famous Blazor demo application provides the case of clicking a button to increment a counter.

blazor click button 1

Let's implement it using Blazor code and JavaScript.


@page "/counter"


<p>Current count: @currentCount</p>

<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>

@functions {
    int currentCount = 0;

    void IncrementCount()



    var currentCount = 0;

    function IncrementCount() 
        document.getElementById('mycnt').innerHTML  =  currentCount++;

<p>my count2: <span id="mycnt"></span></p>

<button class="btn btn-primary" onclick="IncrementCount()">Click me</button>