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

How can i close the mud blazor dialog?

$
0
0

I am simply trying to close this dialog,specifically when i click on the cancel button. i have read the documentation and i dont think i understand how it works any help is greatly appreciated. I have tried looking at the Mud docs , stack posts youtube videos and i cant seem to figure out what the issue is. the close functionality is applied to the close cancel button but nothing is happening.

dialog component

@using MudBlazor<MudDialog><TitleContent>        Dialog Title</TitleContent><DialogContent>        Dialog Content</DialogContent><DialogActions><MudButton style="background-color: red" OnClick="Cancel">Cancel</MudButton><MudButton style="background-color: green;" OnClick="Submit">Ok</MudButton></DialogActions></MudDialog>@code {    [CascadingParameter]    private MudDialogInstance? MudDialog { get; set; }    private void Submit() => MudDialog?.Close(DialogResult.Ok(true));    private void Cancel() => MudDialog?.Cancel();} 

parent component

@using BlazorContactsApp.Services@using BlazorContactsApp.Components@using MudBlazor@inject ContactService ContactService@inject IDialogService DialogService@page "/"<div style="margin: 20px"><MudButton OnClick="OpenDialogAsync" Variant="Variant.Filled" Color="Color.Primary">    Open Simple Dialog</MudButton><h1>Hello, world!</h1><p>Welcome to your new app.</p></div> @if (contacts == null){<p><em>Loading...</em></p>}else{        @foreach (var contact in contacts)        {<MudCard Color="grey" style="border: 1px solid grey; margin: 2rem; width: 20vw; border-radius: 5px"><MudCardContent><MudText Typo="Typo.body2">Name : @contact.Name</MudText></MudCardContent><MudDivider /><MudCardContent><MudText Typo="Typo.body2">Number : @contact.Number</MudText></MudCardContent></MudCard>        }} @code {    private List<ContactsApi.Models.Contact> contacts = new List<ContactsApi.Models.Contact>();         protected override async Task OnInitializedAsync()    {        contacts = await ContactService.GetContactsAsync();    }   private async Task OpenDialogAsync()    {        var options = new DialogOptions { CloseOnEscapeKey = true, CloseButton = true  };        var parameters = new DialogParameters();        var dialog = DialogService.Show<AddContactDialog>("Dialog Title", parameters, options);        var result = await dialog.Result;    } } 

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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