Reputation: 129
I have dialog tha contains a partialview. Is it possible to undo changes that the user makes inside the dialog, if the user decides to cancel the dialog and not to save?
If the user now opens the same dialog the changes are still there even if the user cancelled the dialog. I know that its possible to call the controller and replace the partial view.
Is there any other way?
Upvotes: 1
Views: 1409
Reputation: 22485
sanke - you could store the contents of the div in a .data() element when the partialview is first loaded. Then, if it's cancelled (without saving), just push the .data() back in to div that was created for the dialog.
actions speak louder than words:
// the partial getting loaded
$("#targetDiv").html(data);
var foo = document.body;
jQuery.data(foo, "myKey", data);
then on the cancel you could do the reverse:
// inside the dialog cancel event
var foo = document.body;
var data = jQuery.data(foo, "myKey");
$("#targetDiv").html(data);
give it a try...
Upvotes: 1
Reputation: 174
I don't know much about aspnet mvc but as far as i know about client side and scripting, as long as you work client side with your dialog, what has already been inserted will stay there as the dialog is part of the dom of the page. To work around this kind of problem i usually create myself a 'dialog' class that holds selectors to different fields within the dialoq and that is initialized to default value either when the opendialog method is called or when the dialog is cancelled. The plus value in that is that all your client side scripting for you dialog is contained within one neat javascript class.
Upvotes: 0