如何从外部位置提取HTML块并使用Razor呈现?

时间:2021-07-30 09:35:18

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

我是否可以用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...

我想从给定的位置提取HTML并将其呈现在页面上。这应该是可能的…

Hope this makes sense...

希望这是有道理的……

1 个解决方案

#1


2  

In Razor, no. In HTML yes:

在剃须刀,没有。在HTML是的:

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

实际上你可以使用服务器端代码向远程资源发送一个HTTP请求并显示结果:

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

但是请记住,这将只获取位于指定地址上的内容。如果这是引用外部CSS和javascript文件的HTML页面,则不会检索它们。

#1


2  

In Razor, no. In HTML yes:

在剃须刀,没有。在HTML是的:

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

实际上你可以使用服务器端代码向远程资源发送一个HTTP请求并显示结果:

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

但是请记住,这将只获取位于指定地址上的内容。如果这是引用外部CSS和javascript文件的HTML页面,则不会检索它们。