使用 @Html.Raw 显示 iframe 不像使用 @Html.Raw 显示脚本那样工作
注意:这是用 asp.net mvc 5 编写的。这是我为此使用的技术。
当我使用 @Html.Raw 在我的网站前端为客户显示来自模型的数据时,我习惯于显示某些数据。下面的例子总是对我有用,没有任何问题。
@Html.Raw(Model.MyContentToShowWith_Script)
//FYI: Model.MyContentToShowWith_Script has the following value of a script in my database:
//<script src="https://apps.exampleThirdPartyService.com/p/100201/platform.js" defer></script>
//This returns the third party's data that I need to be displayed.
我当前的问题是,当我想使用 iframe 而不是 script 时,什么也没有发生,我只在页面上看到一堆原始 JavaScript,而不是相同的数据当我不使用iframe时我看到了。 @Html.Raw 不适用于 iframe 吗? 下面是我试图使其工作的代码。我所说的“工作”是指我需要它来准确显示我使用脚本时显示的内容。
@Html.Raw(Model.MyContentToShowWith_iFrame)
//FYI: Model.MyContentToShowWith_iFrame has the following value of an iframe in my database:
//<iframe src="https://apps.exampleThirdPartyService.com/p/100201/platform.js" defer></iframe>
// This SHOULD return the same data as the working example above but just returns the raw js.
例如,如果我要在页面上静态写入 iframe 来替换 动态 Html.Raw 调用,那么 iframe 内容就可以工作。但不是当它来的时候 来自 Html.Raw。 (当然,我将其静态添加到网站只是一个测试,以证明 iframe 确实有效。不过,我会在生产中动态调用它)。
正如您从上面的 2 个场景中看到的,唯一发生变化的是我从使用脚本转向了 iframe。结果是 iframe 不会像使用脚本显示数据那样为我返回数据。
我该如何解决这个问题?在我的情况下,不允许 iframe 显示并使其只显示原始 javascript 到底发生了什么?
Note: This is written in asp.net mvc 5. That is the tech I am using for this.
I am used to displaying certain data when I use @Html.Raw to show data from a Model on the front end of my site for customers. The following example below always works for me with no issues.
@Html.Raw(Model.MyContentToShowWith_Script)
//FYI: Model.MyContentToShowWith_Script has the following value of a script in my database:
//<script src="https://apps.exampleThirdPartyService.com/p/100201/platform.js" defer></script>
//This returns the third party's data that I need to be displayed.
My current issue is that when I want to use iframe in stead of script, nothing happens, I just see a bunch of raw javascript on the page and NOT the same data that I was seeing when I was not using iframe. Does @Html.Raw not work with iframe?
Below is the code that I am trying to make work. By "work" I mean I need it to show exactly what shows up when I use script.
@Html.Raw(Model.MyContentToShowWith_iFrame)
//FYI: Model.MyContentToShowWith_iFrame has the following value of an iframe in my database:
//<iframe src="https://apps.exampleThirdPartyService.com/p/100201/platform.js" defer></iframe>
// This SHOULD return the same data as the working example above but just returns the raw js.
If for example I were to statically write the iframe on the page to replace
the dynamic Html.Raw call, then the iframe content does work. BUT not when its coming
from the Html.Raw. (Of course me adding it statically to the site was just a test to prove that the iframe is indeed working. I would however be calling this dynamically in production).
So as you can see from my 2 scenarios above the only thing that is changing is that I went from using Script to iframe. The result is that iframe does not return the data for me the same way that using script would show it.
How can I fix this? What is actually going on in my situation that does not allow iframe to display and makes it only show the raw javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查下面的问题以解决您的问题,
我们可以使用 httputility.htmldecode
固定的类似类型的问题>
Check the below to fix your issue,
We can use HttpUtility.HtmlDecode
Similar kind of issue fixed here.