dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

Is there a more elegant way to handle reset/cancel with Blazor EditForm? #21110

Closed charleskessler closed 4 years ago

charleskessler commented 4 years ago

EditForm automatically updates the bound object which works great when creating a brand new model instance -- nice and tidy, and very efficient.

However, things get sticky when using EditForm to edit existing model instances.

If I want to give the user the option to back-out of the edit mode -- click Cancel for instance -- I have to implement my component as such: image

Where I store a temp copy of the model (line 21 -- generated by MemberwiseClone), and when the Cancel button is clicked I restore the values of the original model using the temp copy (line 25-30)

This works well enough, but when dealing with dozens of models each with dozens of fields it gets to be a bit of a mess. I know I can use a library such as AutoMapper to make that task much easier, but it still feels very hacky to me.

Is there a more elegant solution to this problem?

javiercn commented 4 years ago

@charleskessler thanks for contacting us.

You are looking for undo functionality I think, and we don't have support for it out of the box. This is something you would need to build yourself.

ghost commented 4 years ago

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.