Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

MudBlazor - MudTable doesn't open MudDialog

$
0
0

I'm creating a MudTable with some data, and I want to open a MudDialog to edit the row data and then save it.

<MudTable T="Company" items="@_Companies" Dense=true Hover=true Bordered=true Striped=true><HeaderContent><MudTh>Name</MudTh><MudTh>Enabled</MudTh><MudTh></MudTh></HeaderContent><RowTemplate><MudTd DataLabel="Name">@context.Name</MudTd><MudTd DataLabel="Enabled">            @if (context.Enabled)            {<MudIcon Icon="@Icons.Material.Filled.Check" Color="Color.Success" />            }            else            {<MudIcon Icon="@Icons.Material.Filled.Close" Color="Color.Error" />            }</MudTd><MudTd DataLabel="Actions" Class="d-flex justify-end"><MudIconButton Icon="@Icons.Material.Outlined.Edit" Color="Color.Primary" Size="Size.Small" OnClick="@(() => OpenDialog(context))" /></MudTd></RowTemplate></MudTable><MudDialog @bind-Open="_dialogOpen" MaxWidth="MaxWidth.Small" CloseButton="true"><DialogContent><MudText Typo="Typo.h6">Edit</MudText></DialogContent><DialogActions><MudButton Color="Color.Primary" OnClick="Save">Save</MudButton><MudButton OnClick="Cancel">Cancel</MudButton></DialogActions></MudDialog>@code {    private IEnumerable<Company> _Companies = new List<Company>();    private bool _dialogOpen = false;    private Company _selectedCompany = new();    protected override void OnInitialized()    {        _Companies = new List<Company>        {            new Company("Company1"),            new Company("Company2"),            new Company("Company3")        };    }    private void OpenDialog(Company company)    {        _dialogOpen = true;    }    private void Save()    {        var original = _Companies.FirstOrDefault(c => c.Name == _selectedCompany.Name);        if (original != null)        {            original.Name = _selectedCompany.Name;            original.Enabled = _selectedCompany.Enabled;        }        _dialogOpen = false;    }    private void Cancel()    {        _dialogOpen = false;    }    public class Company    {        public string Name { get; set; }        public bool Enabled { get; set; }        public Company() {}        public Company(string name)        {            Name = name;            Enabled = true;        }        public Company(string name, bool enabled)        {            Name = name;            Enabled = enabled;        }    }}

Well, with this configuration, I can't open the MudDialog. I have RenderMode = InteractiveServer in routes. If I debug, I see that the OpenDialog is triggered in code, but the MudDialog doesn't show

I try the same in try.mudblazor.com and I see that don't open the MudDialog too.

If you want to try, you'll see that the MudDialog doesn't appears: https://try.mudblazor.com/snippet/cawJOWbBocLefKjg

Some information

.NET version: .NET 9MudBlazor version: 8.0.11Project type: Blazor Server App


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>