从另一个视图获取 div 以显示在当前视图上
因此,我的视图上有这 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用部分视图来完成您想要的事情。不要尝试从另一个视图获取 html。坏主意。
Use partial views to accomplish what you want. Don't try to get html from another view. Bad idea.
在另一个视图中(假设它是部分视图并且在同一页面上),您可以使用 javascript 和 jquery:
如果 HTML 不在同一页面上,则无法从另一个视图获取它。它根本不存在于任何地方。您将需要从服务器重新获取它。话虽这么说,如果您想避免访问数据库或执行一些冗长的任务,您始终可以缓存结果或将它们存储到会话中。
In this other view (assuming it is partial and on the same page) you could use javascript and jquery:
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.