@page "/" <h1>Hello, world!</h1> <MatSelect TValue="Guid" @bind-Value="@SomeViewModelValue.Customer" Disabled="@(!IsAdmin || HasProducts)"> <MatOption Value="new Guid()" Disabled="true">Please select</MatOption> @foreach(var customer in AvailableCustomers) { <MatOption Value="customer.Id">@customer.Name</MatOption> } </MatSelect> <p> HasProducts: @HasProducts </p> <p> IsAdmin: @IsAdmin </p> <p> Disabled: @(!IsAdmin || HasProducts) </p> <MatButton OnClick="ChangeProducts">Change Products</MatButton> @code { SomeViewModel SomeViewModelValue = new() { Customer = new Guid("a7a5a780-1f97-4683-9cf6-1ad956c3da29") }; public bool IsAdmin {get;set;} = true; public bool HasProducts {get;set;} = true; List<Customer> AvailableCustomers = new List<Customer>() { new Customer() { Id = new Guid("a7a5a780-1f97-4683-9cf6-1ad956c3da29"), Name = "Test 1" }, new Customer() { Id = new Guid("54649c26-c4dc-41fb-b8b7-46711c50cc04"), Name = "Test 2" }, new Customer() { Id = new Guid("f8292032-a376-44c2-bcdf-e97e5e6f80b8"), Name = "Test 3" }, new Customer() { Id = new Guid("5b034fd8-0541-4e70-94fb-83d5212e7921"), Name = "Test 4" }, new Customer() { Id = new Guid("738ffb94-89d5-4351-a705-c71a2e087836"), Name = "Test 5" } }; public void ChangeProducts() { HasProducts = HasProducts ? false : true; } class SomeViewModel { public Guid Customer {get;set;} } class Customer { public Guid Id {get;set;} public string Name {get;set;} } }
namespace BlazorFiddleProject { using Microsoft.Extensions.DependencyInjection; public class Startup { public void ConfigureServices(IServiceCollection services) { } // Warning: IComponentsApplicationBuilder - not the original .NET 6.0 interface. This was done to make old saves work. public void Configure(IComponentsApplicationBuilder app) { app.AddComponent<App>("app"); } } }
<!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.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <link href="_content/MatBlazor/dist/matBlazor.css" rel="stylesheet" /> <script src="_content/MatBlazor/dist/matBlazor.js"></script> <style> app { } </style> <script type="text/javascript"> </script> </head> <body> <app>Loading...</app> <script src="_framework/blazor.webassembly.js"></script> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></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.