0

Using

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

and

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

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?

1 Answer 1

0

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';

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");

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

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

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>

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.

Sign up to request clarification or add additional context in comments.

3 Comments

so this would work for html, but surely 1 link = 1 response so how do you get all 3 responses into the document? 3 Posts to the iframe?
@user2330270: The CSS and JS responses don't need to be explicitly loaded. If the HTML document being loaded into the iframe has a link element and a script element which reference the CSS and JS "actions" respectively, the browser will request those resources when the HTML loads in the frame.
genious! you make it sound so simple :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.