从另一个视图获取 div 以显示在当前视图上

发布于 2024-10-16 23:11:39 字数 386 浏览 2 评论 0原文

因此,我的视图上有这 3 个名为 Prepaid.aspx 的 div:

<div id="keyRateTable"></div>
<div id="shockTable"></div>
<div id="valueTable"></div>

单击按钮时它们会填充 HTML,然后 AJAX 通过 JQuery 运行来填充它们的 HTML。

我如何从另一个 MVC 视图访问该 div 的 insideHTML 内容,并将它们也显示在该视图上?我之所以不能像在 Prepaid.aspx 上那样执行相同的过程,是因为该过程可能需要很长时间,并且如果用户已经计算了它,我们只想获取已经生成的 HTML。

So I have these 3 divs on my view called Prepayment.aspx:

<div id="keyRateTable"></div>
<div id="shockTable"></div>
<div id="valueTable"></div>

They get populated with HTML upon a button click, and then AJAX runs through JQuery to populate their HTML.

How do I, from ANOTHER MVC View, access the innerHTML contents of that div, and display them on this view as well? The reason why I can't just do the same process I did on Prepayment.aspx is because that process could take a very long time and if the user already calculated it, we want to just grab the HTML already produced.

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

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

发布评论

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

评论(2

忆悲凉 2024-10-23 23:11:39

使用部分视图来完成您想要的事情。不要尝试从另一个视图获取 html。坏主意。

Use partial views to accomplish what you want. Don't try to get html from another view. Bad idea.

故事还在继续 2024-10-23 23:11:39

在另一个视图中(假设它是部分视图并且在同一页面上),您可以使用 javascript 和 jquery:

var html = $('#shockTable').html();
// TODO: do something with the HTML contained in the shockTable div
// If you want to display this HTML on some other div on the current
// partial you could do this:
$('#someDivOnTheCurrentPartial').html(html);

如果 HTML 不在同一页面上,则无法从另一个视图获取它。它根本不存在于任何地方。您将需要从服务器重新获取它。话虽这么说,如果您想避免访问数据库或执行一些冗长的任务,您始终可以缓存结果或将它们存储到会话中。

In this other view (assuming it is partial and on the same page) you could use javascript and jquery:

var html = $('#shockTable').html();
// TODO: do something with the HTML contained in the shockTable div
// If you want to display this HTML on some other div on the current
// partial you could do this:
$('#someDivOnTheCurrentPartial').html(html);

If the HTML is not on the same page you cannot obtain it from another view. It simply doesn't exist anywhere. You will need to refetch it from the server. This being said if you want to avoid hitting the database or perform some lengthy tasks you could always cache the results or store them into the session.

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