如何从应对渲染HTML和CSS到iframe直接 [英] How do you render html and css into an iframe directly from responses

查看:337
本文介绍了如何从应对渲染HTML和CSS到iframe直接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

return Content(htmlText, "text/html");

return Content(cssText, "text/css");

在我的操作方法,其中的htmlText和cssText是HTML和放大器; CSS串,我怎么能这些反应增加的iframe没有他们我的影响主要应用?

in my action methods where htmlText and cssText are html & css strings, how can I add these responses to an iframe without them effecting my main application?

推荐答案

我怀疑这少做服务器端code和更多地与客户端code。不要以为服务器端code作为渲染一帧,它有没有帧的概念。相反,在客户端code当用户本身包括一个框架接口上,就可以浏览该帧的东西,如:

I suspect this has less to do with server-side code and more to do with client-side code. Don't think of the server-side code as "rendering to a frame", it has no concept of frames. Rather, in client-side code when the user is on an interface which itself includes a frame, you can navigate that frame with something like:

window.frames['framename'].document.location.href = 'someurl';

所以,想象一下,你的服务器端code有一个父行动这使得客户端界面的全部。在该界面(视图)有它本身引用了另一个行动,返回此一个iframe,具体一:

So imagine that your server-side code has one "parent" action which renders the entirety of the client-side interface. In that interface (view) there is an iframe which itself references another action, specifically the one which returns this:

return Content(htmlText, "text/html");

这架即将从这一行动得到它的HTML。服务器端code并不知道这事,它只是响应请求。浏览器从帧(多个)管理请求。

That frame is going to get its HTML from that action. The server-side code doesn't really know anything about this, it's just responding to requests. The browser is managing the requests from the frame(s).

这是父视图可以再触发帧通过更新重新请求其 location.href 如上。

That "parent" view can then trigger the frame to re-request by updating its location.href as above.

此外,你可能想使用POST请求帧,而不是仅仅更改URL(这将只发出GET请求)。在这种情况下,父页面(其中包含帧)可以包含格式目标属性。事情是这样的:

Additionally, you might want to use a POST request to a frame instead of just changing the URL (which would issue only a GET request). In this case the "parent" page (which contains the frame) can contain a form with a target attribute. Something like this:

<form method="post" action="someurl" target="framename">
    form elements go here
</form>

触发该表格上一个提交(无论是与一个提交按钮或JavaScript中code),然后应该是只有框架重装,发帖的形式和渲染后的结果只是在该帧。

Triggering a submit on that form (either with a submit button or in JavaScript code) should then cause only that frame to reload, posting the form and rendering the result just in that frame.

这篇关于如何从应对渲染HTML和CSS到iframe直接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆