-
Hello there, How can I restore back the EditForm value when click on cancel button from Dialog ? on SimpleCustomizedDialog.razor :
|
Beta Was this translation helpful? Give feedback.
Answered by
dvoituron
Dec 6, 2023
Replies: 1 comment 3 replies
-
If you directly bind the properties of the object passed to the dialog box (
But probably the easy way is to use a record data (and not a class).
public record SimplePerson
{
public string Firstname { get; set; } = string.Empty;
public string Lastname { get; set; } = string.Empty;
public int Age { get; set; }
}
private async Task SaveAsync() => await Dialog.CloseAsync(Content);
private async Task CancelAsync() => await Dialog.CancelAsync();
private async Task OpenAsync()
{
var dialog = await DialogService.ShowDialogAsync<SimpleCustomizedDialog>(DialogData with { Age = 42 }, new DialogParameters()
{
// ... existing dialog options
});
var result = await dialog.Result;
if (!result.Cancelled)
{
DialogData = result.Data as SimplePerson;
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
bao86
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you directly bind the properties of the object passed to the dialog box (
SimplePerson
), they are automatically modified when the user changes them via the UI. So there are two solutions in Blazor:SimplePerson
object, which will be bound in the dialog box, and use or not this object by clicking on the Save or Cancel button.SimplePerson
object to the dialog box and manually modify the properties only when the user presses Save.But probably the easy way is to use a record data (and not a class).
Example for the Demo web site:
SimplePerson
file, replace theclass
keyword by arecord