White search icon
News
Roll the dices app in Blazor (visual dices)
ASP.NET Core

Roll the dices app in Blazor (visual dices)

In this article I show you how to create a simple app in blazor where we throw two dices and display a message if the dices is a pair.

|

Blazor

Blazor is a very strong framework to make both visual and logic coding. In this project you can see how easy it is to make a dice rolling app.

The following code is inside the Index.razor file in a Blazor Server App that is created in .NET 6.

Index.razor

By having the dice1 and dice2 variable we can simply use the Random class to get a random number between 1 and 6 and save it inside each dice variable.

We do only need the number because we can put that number inside the src of the image. In this case I created a "img" folder with all 6 images of all the sites of a dice.

Fell free to take these 6 dice images:

Fell free to expand the project and make it even cooler and smarter!


Like what you see?

Buy me a coffee

ZetBit on Spotify

An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.