javascript 如何将视图(cshtml)加载到 iframe 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19094850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:19:26  来源:igfitidea点击:

how do i load a view(cshtml) into an iframe?

javascriptjqueryasp.net-mvciframerazor

提问by sirbombay

I'm trying to load a view into an iframe in another(parent) view using javascript and razor.

我正在尝试使用 javascript 和 razor 将视图加载到另一个(父)视图中的 iframe 中。

I'v tried setting the iframe's src to this var url = '@Url.Action("myaction", "MyController")';

我试过将 iframe 的 src 设置为此 var url = '@Url.Action("myaction", "MyController")';

and this: var url = '@Href("~/myform.cshtml")';without success.

而这: var url = '@Href("~/myform.cshtml")';没有成功。

Thanks

谢谢

Thanks

谢谢

回答by Satpal

If you are using razor engine.

如果您使用剃须刀引擎。

<iframe src = '@Url.Action("myaction", "myController")' width = "100%" 
    height="1000" frameBorder="0"></iframe>

回答by Aviran Cohen

Set the 'src' attribute of the iframe to the action's url.

将 iframe 的 'src' 属性设置为操作的 url。

Example:

例子:

<iframe src ='home/index'></iframe>

Make sure you replace the URL within the srcattribute to the URL of the action.

确保将src属性中的 URL替换为操作的 URL。

An alternative way in Razor:

Razor 中的另一种方法:

<iframe src ='@Url.Action("action name")'></iframe>