如何刷新对话框内容

发布于 2024-10-05 10:26:47 字数 138 浏览 1 评论 0原文

我有一个包含部分视图的对话框。 如果用户决定取消对话框而不保存,是否可以撤消用户在对话框内所做的更改?

如果用户现在打开相同的对话框,即使用户取消了该对话框,更改仍然存在。 我知道可以调用控制器并替换部分视图。

还有其他办法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久随 2024-10-12 10:26:47

sanke - 当首次加载部分视图时,您可以将 div 的内容存储在 .data() 元素中。然后,如果它被取消(不保存),只需将 .data() 推回到为对话框创建的 div 中。

行动胜于雄辩:

// the partial getting loaded
$("#targetDiv").html(data);
var foo = document.body;
jQuery.data(foo, "myKey", data);

然后在取消时您可以做相反的事情:

// inside the dialog cancel event
var foo = document.body;
var data = jQuery.data(foo, "myKey");
$("#targetDiv").html(data);

尝试一下......

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...

探春 2024-10-12 10:26:47

我对 aspnet mvc 不太了解,但据我了解客户端和脚本,只要你在客户端使用对话框工作,已经插入的内容就会保留在那里,因为对话框是 dom 的一部分页。为了解决此类问题,我通常创建一个“dialog”类,该类将选择器保存到 dialoq 中的不同字段,并在调用 opendialog 方法或取消对话框时初始化为默认值。其中的优点是对话框的所有客户端脚本都包含在一个简洁的 javascript 类中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文