How to cancel an edit to an object using MVVM?

后端 未结 7 1531
既然无缘
既然无缘 2020-12-01 08:34

How can I implement cancelation of editing an object using MVVM.

For example: I have a list of customers. I choose one customer an click the button \"Edit\", a dialo

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 08:43

    You could also, in your ViewModel copy the model's state to internal fields, and then expose these and then only set them on the model, when the user actually commits the change.

    Problem could be, that on-the-fly validation will be more troublesome if validation relies on the entity being updated - if this is a requirement you could create a clone of the model to work on and then merging the clone with the actual entity when it is saved.

提交回复
热议问题