Introduction
For the demonstration of the process, we will create a basic calculator app using Blazor and host it on Firebase. This application will not have any server-side code or Web API logic. We will use Visual Studio 2017 to build and publish the application and will use CLI to deploy the application on Firebase.
Prerequisites
You need to install the following prerequisites to create a Blazor application.
- Install the .NET Core 2.1 or above SDK from here
- Install the latest version of Visual Studio 2017 from here
- Install ASP.NET Core Blazor Language Services extension from here
Creating a Blazor application
We will create a basic calculator application for this demo. Since this is a basic calculator, it will take two operands and supports four arithmetic functions—addition, subtraction, multiplication, and passion.
Open Visual Studio and select File >> New >> Project. After selecting the project, a “New Project” dialog will open. Select .NET Core inside the Visual C# menu from the left panel. Then, select “ASP.NET Core Web Application” from the available project types. Put the name of the project as SampleCalculator and press OK.

After clicking on OK, a new dialog will open asking you to select the project template. You can observe two drop-down menus at the top left of the template window. Select “.NET Core” and “ASP.NET Core 2.1” from these dropdowns. Then, select the “Blazor” template and press OK.
This will create your Blazor application. We will now create our calculator component.
Creating the Calculator Component
For this application, we will use the single-page component structure. The logic and the UI will be in the same file.
To create our component, right-click on the SampleCalculator/Pages folder and then select Add >> New Item. An "Add New Item" dialog box will open, asking you to select the desired item template from the provided list of items. Select ASP.NET Core from the left panel, and then select Razor View from the templates panel. Put the name of the file as Calculator.cshtml and click "Add".
Refer to the following screenshot.

Open the Calculator.cshtml file and put the following code into it.
@page "/calculator"
<h1>Basic Calculator Using Blazor</h1>
<hr />
<p>
<p class="row">
<p class="col-sm-3">
<label class="control-label">First Number</label>
</p>
<p class="col-sm-4">
<input class="form-control" type="text" placeholder="Enter First Number" bind="@operand1" />
</p>
</p>
<br />
<p class="row">
<p class="col-sm-3">
<label class="control-label">Second Number</label>
</p>
<p class="col-sm-4">
<input class="form-control" type="text" placeholder="Enter Second Number" bind="@operand2" />
</p>
</p>
<br />
<p class="row">
<p class="col-sm-3">
<label class="control-label">Result</label>
</p>
<p class="col-sm-4">
<input readonly class="form-control" bind="@finalResult" />
</p>
</p>
<br />
<p class="row">
In the HTML part of the code, we have defined two textboxes to read the operand input from the user, and a textbox to display the result of arithmetic operations. We have also defined four buttons, one for each arithmetic operation. The onclick event of the buttons will invoke the methods that will provide the output, once it has performed the corresponding operation on both operands.
In the @functions section, we have defined two properties to bind to the user input value and another property to display the calculation result. To handle our arithmetic operations, we have defined four methods that will perform the desired operations on the operands and set the value of final results that will then bind to the Result field on the UI.
Add the navigation link for this component in the Shared/NavMenu.cshtml file. Press F5 to run the application and you can see the output screen as shown in the image below.

This application is still in the development environment. Before hosting it on Firebase, we need to publish it.






Join the conversation! Your thoughts help the community grow.