Skip to content

How Can I restore data when clicking on No (cancel) using DialogService with IDialogReference #1074

Closed Answered by dvoituron
bao86 asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  1. Create a "Clone" of the SimplePerson object, which will be bound in the dialog box, and use or not this object by clicking on the Save or Cancel button.
  2. Don't bind this 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:

  1. In the SimplePerson file, replace the class keyword by a record
public record SimplePerson
{
    public string Firstname 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@bao86
Comment options

@dvoituron
Comment options

@bao86
Comment options

Answer selected by bao86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants