Posts

Showing posts from June, 2021

Local Storage in Blazor using Blazored

Image
In this blog, you will learn about storing and retrieving values to the Browser's LocalStorage with the help of Blazored. The Blazored LocalStorage library helps to save data in Local Storage. Let's see how to achieve this step by step. Step 1: First, you have to install the Blazored LocalStorage package. If you use Manage Package for Solution look for Blazored.LocalStorage and install the most current package. Otherwise, If you use 'Package Manager Console' then, run the following command. Install-Package Blazored.LocalStorage -Version 4.1.2 Note:- When I write this blog, version 4.1.2 is the latest. Step 2: For Blazor WebAssembly In this step, I have added an AddBlazoredLocalStorage() to the Main method in the Program.cs file. Program.cs using Blazored.LocalStorage; public class Program { public static async Task Main( string [] args) { var builder = WebAssemblyHostBuilder.CreateDefault(arg

JavaScript Interoperability in Blazor

Image
This blog is going to explain JavaScript Interoperability in Blazor. Sometimes it is necessary to use JavaScript in Blazor; you can not avoid that. To use the JavaScript in Blazor, you have to use the IJSRuntime instance via the dependency injection. The InvokeAsync method helps to call the JavaScript function. Let's see how to use JavaScript in Blazor. Step1: Create a new Blazor WebAssembly App In Visual Studio -> Create a New Project -> Blazor App. Provide Project name and Location. Then click the Create button. It will display the Create a New Blazor app window. In there, select 'Blazor WebAssembly App'; Step 2: Create JavaScript File In this step I have created a javascript file with the name SampleJavaScript.js, under wwwroot -> Scripts folder . The following is a code of simple javascript code for adding two integer numbers. \wwwroot\Scripts\SampleJavaScript.js function CalulateSum(firstValue, seco