@page "/"
@using MatBlazor
<EditForm EditContext="_editContext">
<MatSelect Label="Parks" @bind-Value="_parkSelectorModel.ParkId" TValue="int">
@foreach (var park in _parks)
{
<MatOption Value="@park.Id">@park.Name</MatOption>
}
</MatSelect>
<MatButton Disabled="!_editContext.IsModified()">Save</MatButton>
</EditForm>
@code {
EditContext _editContext;
readonly ParkSelectorModel _parkSelectorModel = new ParkSelectorModel();
readonly Park[] _parks = new Park[]
{
new Park()
{
Id = 1,
Name = "Park 1"
},
new Park()
{
Id = 2,
Name = "Park 2"
}
};
protected override void OnInitialized()
{
_editContext = new EditContext(_parkSelectorModel);
_editContext.OnFieldChanged += (sender, args) =>
{
StateHasChanged();
};
}
public class Park
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ParkSelectorModel
{
public int ParkId { get; set; }
}
}