4

Is there anyway I can do the following code in razor?

<div>
   <c:import url="http://hostName/HTML-file-name/" />
</div> 

I would like to pull HTML from a given location and render it on a page. This should be possible...

Hope this makes sense...

2
  • It's mandatory to render the html from the view? because you can render this from the controller
    – Jorge
    Jan 25, 2013 at 14:39
  • Hi, we are using razor, so ideally I wanted to do it via that...
    – Vikita
    Jan 25, 2013 at 14:39

1 Answer 1

3

In Razor, no. In HTML yes:

<div>
    <iframe src="http://hostName/HTML-file-name/"></iframe>
</div>

Well actually you could use server side code to send an HTTP request to the remote resource and display the result inline:

<div>
    @Html.Raw(new System.Net.WebClient().DownloadString("http://hostName/HTML-file-name/"))
</div>

But bear in mind that this will fetch only the content situated on the specified address. If this is for example an HTML page referencing external CSS, and javascript files, they will not be retrieved.

2
  • Also, that should happen in the controller.
    – SLaks
    Jan 25, 2013 at 15:30
  • Thank you, Darin! I'll try this and update this question accordingly.
    – Vikita
    Jan 25, 2013 at 17:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.