Getting Started with Blazor Barcode Generator Component in WASM App
26 Aug 20265 minutes to read
This section briefly explains how to include the Blazor Barcode Generator component in a Blazor WebAssembly App using Visual Studio, Visual Studio Code, and the .NET CLI.
NOTE
The Blazor Diagram component requires .NET 8.0 or later and a modern browser with ES6 and WebAssembly support.
Create a new Blazor WebAssembly (Standalone) App
Prerequisites
Create a Blazor WebAssembly App using Visual Studio via Microsoft Templates or the Syncfusion® Blazor Extension.
Prerequisites
Run the following command to create a new Blazor WebAssembly App.
dotnet new blazorwasm -o BlazorApp
cd BlazorAppAlternatively, create a Blazor WebAssembly App using Visual Studio Code via Microsoft Templates or the Syncfusion® Blazor Extension, or the C# Dev Kit extension.
Install the latest version of .NET SDK. If the .NET SDK is already installed, determine the installed version by running the following command in a command prompt (Windows), terminal (macOS), or command shell (Linux).
Run the following command to create a new Blazor WebAssembly App.
dotnet new blazorwasm -o BlazorApp
cd BlazorAppInstall the required Blazor packages
Install the Syncfusion.Blazor.BarcodeGenerator NuGet packages. All Syncfusion Blazor packages are available on nuget.org. See the NuGet packages topic for details.
- Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution.
- Search the required NuGet packages (
Syncfusion.Blazor.BarcodeGenerator) and install them.
Alternatively, run the following commands in the Package Manager Console(Tools → NuGet Package Manager → Package Manager Console) to achieve the same.
Install-Package Syncfusion.Blazor.BarcodeGenerator -Version 34.2.2Open the terminal and run the following commands.
dotnet add package Syncfusion.Blazor.BarcodeGenerator -v 34.2.2Open the command prompt and run the following commands.
dotnet add package Syncfusion.Blazor.BarcodeGenerator -v 34.2.2Import namespaces
After the packages are installed, open the ~/_Imports.razor file and import the Syncfusion.Blazor and Syncfusion.Blazor.BarcodeGenerator namespaces.
@using Syncfusion.Blazor
@using Syncfusion.Blazor.BarcodeGeneratorNOTE
All Syncfusion Blazor packages are available on nuget.org. See the NuGet packages topic for details.
Register the Blazor service
Open the Program.cs file in Blazor WebAssembly App and register the Blazor service and include the required namespace reference using Syncfusion.Blazor; at the top.
builder.Services.AddSyncfusionBlazor();Add script resource
Include the required script references at the end of the <body> section in the ~wwwroot/index.html file to enable Barcode Generator functionality.
<script src="_content/Syncfusion.Blazor.BarcodeGenerator/scripts/sf-barcode.min.js" type="text/javascript"></script>Add Blazor Barcode Generator component
Open a Razor file located in the ~/Pages/*.razor (for example, Home.razor) and add the Blazor Barcode Generator component inside the razor file.
<SfBarcodeGenerator Width="200px" Height="150px" Type="@BarcodeType.Codabar" Value="123456789"></SfBarcodeGenerator>Run the application
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. The Blazor Barcode Generator component will render in your default web browser.
Open the terminal and run the following command.
dotnet runOpen the command prompt and run the following command.
dotnet run
NOTE
Add the QR Code Generator component
Add a QR code to the Barcode Generator component.
<SfQRCodeGenerator Width="200px" Height="150px" Value="Syncfusion"></SfQRCodeGenerator>
Add the Data Matrix Generator component
Add a Data Matrix code to the Barcode Generator component.
<SfDataMatrixGenerator Width="200px" Height="150px" Value="SYNCFUSION"></SfDataMatrixGenerator>