Single Page Application In Blazor With Azure Table Storage

We will create a single page application in Blazor. We will store the data in Azure Table Storage. We will see all the CRUD operations in this Blazor project. For that, we will create a Person app with storing Id, Name, Country, Age and Gender.

Introduction

 
In this post, we will create a single page application in Blazor. We will store the data in Azure Table Storage. Also, we will see all the CRUD operations in this Blazor project. For that, we will create a Person app by storing the Id, Name, Country, Age, and Gender. We will generate the Id column value as GUID.
 

About Azure Table Storage

 
Azure Table Storage is a service that stores the structured NoSQL data in the cloud, providing a key/attribute store with a schemaless design. Table storage is always schema-less. Access to Table Storage data is fast and cost-effective for many types of applications and it is typically lower in cost than traditional SQL for similar volumes of data.
 
You can use table storage to store the flexible datasets like user data for web applications, device information, address books, or any other types of metadata that your service requires. You can store any number of entities in a table, and a storage account may contain any number of tables, up to the capacity limit of your storage account.
 
The “PartitionKey” and “RowKey” are major elements in Azure Table Storage and are used to save the data in a structured way, like indexing in SQL. “RowKeymainly acts as a primary key in SQL.
 
You can refer to the below article to get more details on Azure Table Storage.
 

About Blazor Framework

 
Blazor is (still an experimental) .NET web framework from Microsoft using C#/Razor and HTML that runs in the browser with Web Assembly. Blazor provides all the benefits of a client-side web UI framework using .NET on the client and optionally on the server.
I have already written many articles on Blazor for you good people on C# Corner. If you are new to it, please refer to the below articles to get started with Blazor.
After choosing the resource group, you can give a valid and unique (globally) name to the storage account. Click the “Review + create” button to validate the service details and then click the “Create” button to start the deployment of the storage account.
 
Single Page Application in Blazor with Azure Table Storage 

After a few moments, our storage account service will be ready.

Go to the Resource and choose “Configuration” blade and select “Disabled” option under "Secure transfer required". Click the “Save” button to save the settings. If you do not choose this, you can’t connect Azure Table Storage to Blazor application without HTTPS.
 
Single Page Application in Blazor with Azure Table Storage 
 
Go to “Overview” blade and choose “Tables” option to create a new table.
 
Single Page Application in Blazor with Azure Table Storage 

We can add multiple tables to the same storage account depending on the capacity of the storage account. Each table can contain multiple entities and each entity can store multiple documents. We will create a “Person” entity using C# in our Blazor project later.

You can click the “Access keys” blade and copy the connection string and save that to a secure place. We will use this connection string later in our Blazor application.
 

Create a Blazor project in Visual Studio 2017

 
We can create a new Blazor project using Visual Studio 2017 (I am using free community edition). Currently, there are three types of templates available for Blazor. We can choose Blazor (ASP.NET Core hosted) template.
 
Single Page Application in Blazor with Azure Table Storage 
 
Our solution will be ready shortly. Please note that there are three projects created in our solution - “Client”, “Server”, and “Shared”.
 
Single Page Application in Blazor with Azure Table Storage 

By default, Blazor creates many files in these three projects. We can remove all the unwanted files like “Counter.cshtml”, “FetchData.cshtml”, “SurveyPrompt.cshtml” from the Client project, “SampleDataController.cs” file from the Server project, and remove “WeatherForecast.cs” file from the Shared project.

We are going to process Azure Table Storage operations usingWindowsAzure.Storage” NuGet package. We must install this package in “Shared” project.
 
Single Page Application in Blazor with Azure Table Storage 
 
Create a “Models” folder in “Shared” project and create a “Person” class inside this folder.
 
Person.cs
  1. using Microsoft.WindowsAzure.Storage.Table;  
  2. namespace BlazorAzureTableStorage.Shared.Models {  
  3.     public class Person: TableEntity {  
  4.         public string Id {  
  5.             get;  
  6.             set;  
  7.         }  
  8.         public string Name {  
  9.             get;  
  10.             set;  
  11.         }  
  12.         public string Country {  
  13.             get;  
  14.             set;  
  15.         }  
  16.         public int Age {  
  17.             get;  
  18.             set;  
  19.         }  
  20.         public string Gender {  
  21.             get;  
  22.             set;  
  23.         }  
  24.     }  
  25. }  

Please note that we have inherited this class from the “TableEntity” class. We will use the “PartitionKey” and “RowKey” properties from the TableEntity class.

We can create a “DataAccess” folder in the Shared project. We then create “AzureTableSettings” inside this folder.
 
AzureTableSettings.cs
  1. namespace BlazorAzureTableStorage.Shared.DataAccess {  
  2.     public class AzureTableSettings {  
  3.         public AzureTableSettings(string connectionString, string tableName) {  
  4.             TableName = tableName;  
  5.             ConnectionString = connectionString;  
  6.         }  
  7.         public string TableName {  
  8.             get;  
  9.         }  
  10.         public string ConnectionString {  
  11.             get;  
  12.             set;  
  13.         }  
  14.     }  

This file contains the ConnectionString and table name properties which we will later use to establish the CRUD operations.

Create an “IAzureTableStorage” interface to define the method declaration for CRUD operations.
 
IAzureTableStorage.cs
  1. using Microsoft.WindowsAzure.Storage.Table;  
  2. using System.Collections.Generic;  
  3. using System.Threading.Tasks;  
  4. namespace BlazorAzureTableStorage.Shared.DataAccess {  
  5.     public interface IAzureTableStorage < T > where T: TableEntity, new() {  
  6.         Task Delete(string rowKey);  
  7.         Task < T > GetItem(string rowKey);  
  8.         Task < List < T >> GetList();  
  9.         Task Insert(T item);  
  10.         Task Update(T item);  
  11.     }  
  12. }  
We can now implement the above interface in “AzureTableStorage” class.
 
AzureTableStorage.cs
  1. using Microsoft.WindowsAzure.Storage;  
  2. using Microsoft.WindowsAzure.Storage.Table;  
  3. using System.Collections.Generic;  
  4. using System.Threading.Tasks;  
  5. namespace BlazorAzureTableStorage.Shared.DataAccess {  
  6.     public class AzureTableStorage < T > : IAzureTableStorage < T > where T: TableEntity, new() {  
  7.         private readonly AzureTableSettings settings;  
  8.         public AzureTableStorage(AzureTableSettings settings) {  
  9.             this.settings = settings;  
  10.         }  
  11.         public async Task < List < T >> GetList() {  
  12.             //Table  
  13.             CloudTable table = await GetTableAsync();  
  14.             //Query  
  15.             TableQuery < T > query = new TableQuery < T > ();  
  16.             List < T > results = new List < T > ();  
  17.             TableContinuationToken continuationToken = null;  
  18.             do {  
  19.                 TableQuerySegment < T > queryResults = await table.ExecuteQuerySegmentedAsync(query, continuationToken);  
  20.                 continuationToken = queryResults.ContinuationToken;  
  21.                 results.AddRange(queryResults.Results);  
  22.             } while (continuationToken != null);  
  23.             return results;  
  24.         }  
  25.         public async Task < T > GetItem(string rowKey) {  
  26.             //Table  
  27.             CloudTable table = await GetTableAsync();  
  28.             //Operation  
  29.             TableOperation operation = TableOperation.Retrieve < T > ("", rowKey);  
  30.             //Execute  
  31.             TableResult result = await table.ExecuteAsync(operation);  
  32.             return (T)(dynamic) result.Result;  
  33.         }  
  34.         public async Task Insert(T item) {  
  35.             //Table  
  36.             CloudTable table = await GetTableAsync();  
  37.             //Operation  
  38.             TableOperation operation = TableOperation.Insert(item);  
  39.             //Execute  
  40.             await table.ExecuteAsync(operation);  
  41.         }  
  42.         public async Task Update(T item) {  
  43.             //Table  
  44.             CloudTable table = await GetTableAsync();  
  45.             //Operation  
  46.             TableOperation operation = TableOperation.InsertOrReplace(item);  
  47.             //Execute  
  48.             await table.ExecuteAsync(operation);  
  49.         }  
  50.         public async Task Delete(string rowKey) {  
  51.             //Item  
  52.             T item = await GetItem(rowKey);  
  53.             //Table  
  54.             CloudTable table = await GetTableAsync();  
  55.             //Operation  
  56.             TableOperation operation = TableOperation.Delete(item);  
  57.             //Execute  
  58.             await table.ExecuteAsync(operation);  
  59.         }  
  60.         private async Task < CloudTable > GetTableAsync() {  
  61.             //Account  
  62.             CloudStorageAccount storageAccount = CloudStorageAccount.Parse(this.settings.ConnectionString);  
  63.             //Client  
  64.             CloudTableClient tableClient = storageAccount.CreateCloudTableClient();  
  65.             //Table  
  66.             CloudTable table = tableClient.GetTableReference(this.settings.TableName);  
  67.             await table.CreateIfNotExistsAsync();  
  68.             return table;  
  69.         }  
  70.     }  
  71. }  
We can create another interface “IPersonService” for the Person service. It will contain all the method declarations in the previous interface IAzureTableStorage. Only the method names are changed.
 
IPersonService.cs 
  1. using BlazorAzureTableStorage.Shared.Models;  
  2. using System.Collections.Generic;  
  3. using System.Threading.Tasks;  
  4. namespace BlazorAzureTableStorage.Shared.DataAccess {  
  5.     public interface IPersonService {  
  6.         Task AddPerson(Person item);  
  7.         Task DeletePerson(string id);  
  8.         Task < Person > GetPerson(string id);  
  9.         Task < List < Person >> GetPeople();  
  10.         Task UpdatePerson(Person item);  
  11.     }  
Create a service class “PersonService” and implement the interface IPersonService.
 
PersonService.cs
  1. using BlazorAzureTableStorage.Shared.Models;  
  2. using System.Collections.Generic;  
  3. using System.Threading.Tasks;  
  4. namespace BlazorAzureTableStorage.Shared.DataAccess {  
  5.     public class PersonService: IPersonService {  
  6.         private readonly IAzureTableStorage < Person > repository;  
  7.         public PersonService(IAzureTableStorage < Person > repository) {  
  8.             this.repository = repository;  
  9.         }  
  10.         public async Task < List < Person >> GetPeople() {  
  11.             return await this.repository.GetList();  
  12.         }  
  13.         public async Task < Person > GetPerson(string id) {  
  14.             return await this.repository.GetItem(id);  
  15.         }  
  16.         public async Task AddPerson(Person item) {  
  17.             await this.repository.Insert(item);  
  18.         }  
  19.         public async Task UpdatePerson(Person item) {  
  20.             await this.repository.Update(item);  
  21.         }  
  22.         public async Task DeletePerson(string id) {  
  23.             await this.repository.Delete(id);  
  24.         }  
  25.     }  
  26. }  
We can go to the “Server” project and add “appsettings.json”. This JSON file will be used for configuration settings. We will keep the Azure Table Storage connection string and table name inside this JSON.
 
appsettings.json
  1. {  
  2.     "ConnectionString""DefaultEndpointsProtocol=https;AccountName=sarathlal;AccountKey=<Your Access Key>;EndpointSuffix=core.windows.net",  
  3.     "TableName""SarathTable"  
  4. }   
We can modify the “Startup” class with the below code.
 
Startup.cs
  1. using BlazorAzureTableStorage.Shared.DataAccess;  
  2. using BlazorAzureTableStorage.Shared.Models;  
  3. using Microsoft.AspNetCore.Blazor.Server;  
  4. using Microsoft.AspNetCore.Builder;  
  5. using Microsoft.AspNetCore.Hosting;  
  6. using Microsoft.AspNetCore.ResponseCompression;  
  7. using Microsoft.Extensions.Configuration;  
  8. using Microsoft.Extensions.DependencyInjection;  
  9. using System.Linq;  
  10. using System.Net.Mime;  
  11. namespace BlazorAzureTableStorage.Server {  
  12.     public class Startup {  
  13.         public static IConfiguration Configuration;  
  14.         public Startup(IConfiguration configuration) {  
  15.             Configuration = configuration;  
  16.         }  
  17.         public void ConfigureServices(IServiceCollection services) {  
  18.             services.AddScoped < IAzureTableStorage < Person >> (factory => {  
  19.                 return new AzureTableStorage < Person > (new AzureTableSettings(connectionString: Configuration["ConnectionString"], tableName: Configuration["TableName"]));  
  20.             });  
  21.             services.AddScoped < IPersonService, PersonService > ();  
  22.             services.AddMvc();  
  23.             services.AddResponseCompression(options => {  
  24.                 options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new [] {  
  25.                     MediaTypeNames.Application.Octet,  
  26.                         WasmMediaTypeNames.Application.Wasm,  
  27.                 });  
  28.             });  
  29.         }  
  30.         public void Configure(IApplicationBuilder app, IHostingEnvironment env) {  
  31.             app.UseResponseCompression();  
  32.             if (env.IsDevelopment()) {  
  33.                 app.UseDeveloperExceptionPage();  
  34.             }  
  35.             app.UseMvc(routes => {  
  36.                 routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}");  
  37.             });  
  38.             app.UseBlazor < Client.Program > ();  
  39.         }  
  40.     }  
  41.  
We have injected the dependencies for Person service in this class.
 
Single Page Application in Blazor with Azure Table Storage 

Create the “PeopleController” class inside the “Controllers” folder. Copy the below code to this class.

PeopleController.cs
  1. using BlazorAzureTableStorage.Shared.DataAccess;  
  2. using BlazorAzureTableStorage.Shared.Models;  
  3. using Microsoft.AspNetCore.Mvc;  
  4. using System;  
  5. using System.Collections.Generic;  
  6. using System.Linq;  
  7. using System.Threading.Tasks;  
  8. namespace BlazorAzureTableStorage.Server.Controllers {  
  9.     [Route("api/[controller]")]  
  10.     [ApiController]  
  11.     public class PeopleController: Controller {  
  12.         private readonly IPersonService service;  
  13.         public PeopleController(IPersonService service) {  
  14.                 this.service = service;  
  15.             }  
  16.             [HttpGet]  
  17.         public async Task < List < Person >> Get() {  
  18.                 var model = await service.GetPeople();  
  19.                 return model.ToList();  
  20.             }  
  21.             [HttpGet("{id}")]  
  22.         public async Task < Person > Get(string id) {  
  23.                 var model = await service.GetPerson(id);  
  24.                 return model;  
  25.             }  
  26.             [HttpPost]  
  27.         public async Task < bool > Create([FromBody] Person person) {  
  28.                 if (person == nullreturn false;  
  29.                 person.Id = Guid.NewGuid().ToString();  
  30.                 person.PartitionKey = "";  
  31.                 person.RowKey = person.Id;  
  32.                 if (!ModelState.IsValid) return false;  
  33.                 await service.AddPerson(person);  
  34.                 return true;  
  35.             }  
  36.             [HttpPut("{id}")]  
  37.         public async Task < bool > Update(string id, [FromBody] Person person) {  
  38.                 person.Id = id;  
  39.                 person.PartitionKey = "";  
  40.                 person.RowKey = person.Id;  
  41.                 if (!ModelState.IsValid) return false;  
  42.                 await service.UpdatePerson(person);  
  43.                 return true;  
  44.             }  
  45.             [HttpDelete("{id}")]  
  46.         public async Task Delete(string id) {  
  47.             await service.DeletePerson(id);  
  48.         }  
  49.     }  

We have defined all the HTTP methods inside the above API class.

We can go to “Client” project and modify the “NavMenu.cshtml” Razor View file inside “Shared” folder with the below code.

NavMenu.cshtml
  1. <div class="top-row pl-4 navbar navbar-dark">  
  2.     <a class="navbar-brand" href="">Blazor Azure Table Storage</a>  
  3.     <button class="navbar-toggler" onclick=@ToggleNavMenu>  
  4.         <span class="navbar-toggler-icon"></span>  
  5.     </button>  
  6. </div>  
  7. <div class=@(collapseNavMenu ? "collapse" : null) onclick=@ToggleNavMenu>  
  8.     <ul class="nav flex-column">  
  9.         <li class="nav-item px-3">  
  10.             <NavLink class="nav-link" href="" Match=NavLinkMatch.All>  
  11.                 <span class="oi oi-home" aria-hidden="true"></span> Home </NavLink>  
  12.         </li>  
  13.         <li class="nav-item px-3">  
  14.             <NavLink class="nav-link" href="/listpeople">  
  15.                 <span class="oi oi-plus" aria-hidden="true"></span> People Details </NavLink>  
  16.         </li>  
  17.     </ul>  
  18. </div> @functions { bool collapseNavMenu = truevoid ToggleNavMenu() { collapseNavMenu = !collapseNavMenu; } }  

The above file handles the page navigation. We will show a “People Details” menu along with the “Home” menu.

Create a new Razor View file, such as “ListPeople.cshtml” inside the “Pages” folder and add the below code.
 
ListPeople.cshtml
  1. @using BlazorAzureTableStorage.Shared.Models  
  2. @page "/listpeople"  
  3. @inject HttpClient Http  
  4. <h1>People Details</h1>  
  5. <p>  
  6.    <a href="/addperson">Create New Person</a>  
  7. </p>  
  8. @if (people == null)  
  9. {  
  10.    <p><em>Loading...</em></p>  
  11. }  
  12. else  
  13. {  
  14. <table class='table'>  
  15.     <thead>  
  16.         <tr>  
  17.             <th>Name</th>  
  18.             <th>Country</th>  
  19.             <th>Age</th>  
  20.             <th>Gender</th>  
  21.         </tr>  
  22.     </thead>  
  23.     <tbody> @foreach (var person in people) { <tr>  
  24.             <td>@person.Name</td>  
  25.             <td>@person.Country</td>  
  26.             <td>@person.Age</td>  
  27.             <td>@person.Gender</td>  
  28.             <td>  
  29.                 <a href='/editperson/@person.Id'>Edit</a>  
  30.                 <a href='/deleteperson/@person.Id'>Delete</a>  
  31.             </td>  
  32.         </tr> } </tbody>  
  33. </table>  
  34. }  
  35. @functions {  
  36.     Person[] people;  
  37.     protected override async Task OnInitAsync() {  
  38.         people = await Http.GetJsonAsync < Person[] > ("/api/people");  
  39.     }  
  40. }  

The above Razor View will display all the Person details from Azure Table Storage.

We can add other three Razor View files for adding, editing, and deleting the Person data.
 
AddPerson.cshtml
  1. @using BlazorAzureTableStorage.Shared.Models  
  2. @page "/addperson"  
  3. @inject HttpClient Http  
  4. @inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper  
  5. <h3>Create Person</h3>  
  6. <hr />  
  7. <form>  
  8.     <div class="row">  
  9.         <div class="col-md-8">  
  10.             <div class="form-group">  
  11.                 <label for="Name" class="control-label">Name</label>  
  12.                 <input for="Name" class="form-control" bind="@person.Name" />  
  13.             </div>  
  14.             <div class="form-group">  
  15.                 <label for="Country" class="control-label">Country</label>  
  16.                 <input for="Country" class="form-control" bind="@person.Country" />  
  17.             </div>  
  18.             <div class="form-group">  
  19.                 <label for="Age" class="control-label">Age</label>  
  20.                 <input for="Age" class="form-control" bind="@person.Age" />  
  21.             </div>  
  22.             <div class="form-group">  
  23.                 <label for="Gender" class="control-label">Gender</label>  
  24.                 <select for="Gender" class="form-control" bind="@person.Gender">  
  25.                     <option value="">-- Select Gender --</option>  
  26.                     <option value="Male">Male</option>  
  27.                     <option value="Female">Female</option>  
  28.                 </select>  
  29.             </div>  
  30.         </div>  
  31.     </div>  
  32.     <div class="row">  
  33.         <div class="col-md-4">  
  34.             <div class="form-group">  
  35.                 <input type="button" class="btn btn-default" onclick="@(async () => await CreatePerson())" value="Save" />  
  36.                 <input type="button" class="btn" onclick="@Cancel" value="Cancel" />  
  37.             </div>  
  38.         </div>  
  39.     </div>  
  40. </form>  
  41. @functions {  
  42.     Person person = new Person();  
  43.     protected async Task CreatePerson() {  
  44.         await Http.SendJsonAsync(HttpMethod.Post, "/api/people", person);  
  45.         UriHelper.NavigateTo("/listpeople");  
  46.     }  
  47.     void Cancel() {  
  48.         UriHelper.NavigateTo("/listpeople");  
  49.     }  
  50. }  
EditPerson.cshtml 
  1. @using BlazorAzureTableStorage.Shared.Models  
  2. @page "/editperson/{id}"  
  3. @inject HttpClient Http  
  4. @inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper  
  5. <h3>Edit Person</h3>  
  6. <hr />  
  7. <form>  
  8.     <div class="row">  
  9.         <div class="col-md-8">  
  10.             <div class="form-group">  
  11.                 <label for="Name" class="control-label">Name</label>  
  12.                 <input for="Name" class="form-control" bind="@person.Name" />  
  13.             </div>  
  14.             <div class="form-group">  
  15.                 <label for="Country" class="control-label">Country</label>  
  16.                 <input for="Country" class="form-control" bind="@person.Country" />  
  17.             </div>  
  18.             <div class="form-group">  
  19.                 <label for="Age" class="control-label">Age</label>  
  20.                 <input for="Age" class="form-control" bind="@person.Age" />  
  21.             </div>  
  22.             <div class="form-group">  
  23.                 <label for="Gender" class="control-label">Gender</label>  
  24.                 <select for="Gender" class="form-control" bind="@person.Gender">  
  25.                     <option value="">-- Select Gender --</option>  
  26.                     <option value="Male">Male</option>  
  27.                     <option value="Female">Female</option>  
  28.                 </select>  
  29.             </div>  
  30.         </div>  
  31.     </div>  
  32.     <div class="row">  
  33.         <div class="form-group">  
  34.             <input type="button" class="btn btn-default" onclick="@(async () => await UpdatePerson())" value="Save" />  
  35.             <input type="button" class="btn" onclick="@Cancel" value="Cancel" />  
  36.         </div>  
  37.     </div>  
  38. </form>  
  39. @functions {  
  40.     [Parameter]  
  41.     string id {  
  42.         get;  
  43.         set;  
  44.     }  
  45.     Person person = new Person();  
  46.     protected override async Task OnInitAsync() {  
  47.         person = await Http.GetJsonAsync < Person > ("/api/people/" + id);  
  48.     }  
  49.     protected async Task UpdatePerson() {  
  50.         await Http.SendJsonAsync(HttpMethod.Put, "api/people/" + id, person);  
  51.         UriHelper.NavigateTo("/listpeople");  
  52.     }  
  53.     void Cancel() {  
  54.         UriHelper.NavigateTo("/listpeople");  
  55.     }  
  56. }  
DeletePerson.cshtml
  1. @using BlazorAzureTableStorage.Shared.Models  
  2. @page "/deleteperson/{id}"  
  3. @inject HttpClient Http  
  4. @inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper  
  5. <h2>Delete</h2>  
  6. <p>Are you sure you want to delete this Person with Id :<b> @id</b></p>  
  7. <br />  
  8. <div class="col-md-4">  
  9.     <table class="table">  
  10.         <tr>  
  11.             <td>Name</td>  
  12.             <td>@person.Name</td>  
  13.         </tr>  
  14.         <tr>  
  15.             <td>Country</td>  
  16.             <td>@person.Country</td>  
  17.         </tr>  
  18.         <tr>  
  19.             <td>Age</td>  
  20.             <td>@person.Age</td>  
  21.         </tr>  
  22.         <tr>  
  23.             <td>Gender</td>  
  24.             <td>@person.Gender</td>  
  25.         </tr>  
  26.     </table>  
  27.     <div class="form-group">  
  28.         <input type="button" value="Delete" onclick="@(async () => await Delete())" class="btn btn-default" />  
  29.         <input type="button" value="Cancel" onclick="@Cancel" class="btn" />  
  30.     </div>  
  31. </div>  
  32. @functions {  
  33.     [Parameter]  
  34.     string id {  
  35.         get;  
  36.         set;  
  37.     }  
  38.     Person person = new Person();  
  39.     protected override async Task OnInitAsync() {  
  40.         person = await Http.GetJsonAsync < Person > ("/api/people/" + id);  
  41.     }  
  42.     protected async Task Delete() {  
  43.         await Http.DeleteAsync("api/people/" + id);  
  44.         UriHelper.NavigateTo("/listpeople");  
  45.     }  
  46.     void Cancel() {  
  47.         UriHelper.NavigateTo("/listpeople");  
  48.     }  
  49. }  

We can also modify the “Index.cshtml” file with the below code.

Index.cshtml
  1. @page "/"  
  2. <h3>Blazor Application With Azure Table Storage</h3>  
  3. <p>  
  4.    We will create a single page application in Blazor. We will store the data in Azure Table Storage.  
  5.    We will see all the CRUD operation in this Blazor project.  
  6.    We will create a Person app with Id, Name, Country, Age, and Gender.  
  7. </p>  

Run the application.

We have completed all the coding part. We can run the Blazor application.

Single Page Application in Blazor with Azure Table Storage 
 
We can click the “People Details” link and open the "List People" page. Click the “Create New Person” link to add a new person.
 
Single Page Application in Blazor with Azure Table Storage 
 
After saving the data, we can get the Person details in the grid. We can click “Edit” to modify the data.
 
Single Page Application in Blazor with Azure Table Storage 
 
I have modified the person name. We can add some more persons and their details. We get all the persons' data in a grid format.
 
Single Page Application in Blazor with Azure Table Storage 
 
We can also delete the data by clicking the “Delete” link. It will ask for confirmation before deleting the data.
 
Single Page Application in Blazor with Azure Table Storage 

After clicking the “Delete” button, our persons' data will be deleted.

In this post, we have created a storage account in Azure portal and created table storage. We have created a Blazor project in Visual Studio and performed all CRUD operations with Azure Table Storage.

References

  • https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-overview
  • https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet
  • https://www.c-sharpcorner.com/article/azure-table-storage-in-asp-net-core-2-0/

We can see more exciting features of Blazor in upcoming posts.