@page "/" @using System.Collections.Generic; @using System.Linq; @if (Terminals == null) { <p><em>Loading...</em></p> } else { <select bind="@SelectedTerminalId"> <option value=@(0)></option> @foreach (var Terminal in Terminals) { <option value="@Terminal.TerminalId">@Terminal.Name</option> } </select> } @if (SelectedTerminalId != default) { var prices = Terminals.Single(x => x.TerminalId == SelectedTerminalId).Prices; <select bind="@SelectedPriceSettingId"> <option value=@(0)></option> @foreach (var price in prices) { <option value="@price.Id">@price.Name (@price.Value)</option> } </select> } @functions { private static readonly List<Terminal> Terminals = new List<Terminal>{ new Terminal{ TerminalId = 1, Name = "NYC", Prices = new List<PriceSetting> { new PriceSetting{Id = 1, Name = "test1", Value = 104.13m}, new PriceSetting{Id = 2, Name = "test2", Value = 105.13m } } }, new Terminal{ TerminalId = 2, Name = "LHR", Prices = new List<PriceSetting> { new PriceSetting{Id = 3, Name = "test3", Value = 106.13m} } } }; int _selectedTerminalId; int SelectedTerminalId { get => _selectedTerminalId; set { _selectedTerminalId = value; SelectedPriceSettingId = default; } } int SelectedPriceSettingId { get; set; } }
namespace BlazorFiddleProject { using Microsoft.AspNetCore.Blazor.Builder; using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IBlazorApplicationBuilder app) { app.AddComponent<App>("app"); } } public class PriceSetting { public int Id { get; set; } public string Name { get; set; } public decimal Value { get; set; } } public class Terminal { public int TerminalId { get; set; } public string Name { get; set; } public List<PriceSetting> Prices { get; set; } } }
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width"> <title>BlazorFiddleProject</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/> <style> </style> <script type="text/javascript"> </script> </head> <body> <app>Loading...</app> <script src="_framework/blazor.webassembly.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script> </body> </html>

Add component

BlazorFiddle was updated from Blazor 0.7 to .NET 6.0. Your old source code could not work. You need to upgrade to latest.