Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pull HTML block from a external location and render it with Razor?

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

like image 425
Vikita Avatar asked Sep 11 '25 19:09

Vikita


1 Answers

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.

like image 129
Darin Dimitrov Avatar answered Sep 13 '25 09:09

Darin Dimitrov