how do i load a view(cshtml) into an iframe?
18,318
Solution 1
If you are using razor engine.
<iframe src = '@Url.Action("myaction", "myController")' width = "100%"
height="1000" frameBorder="0"></iframe>
Solution 2
Set the 'src' attribute of the iframe to the action's url.
Example:
<iframe src ='home/index'></iframe>
Make sure you replace the URL within the src
attribute to the URL of the action.
An alternative way in Razor:
<iframe src ='@Url.Action("action name")'></iframe>
Comments
-
sirbombay almost 2 years
I'm trying to load a view into an iframe in another(parent) view using javascript and razor.
I'v tried setting the iframe's src to this
var url = '@Url.Action("myaction", "MyController")';
and this:
var url = '@Href("~/myform.cshtml")';
without success.Thanks
Thanks
-
sirbombay over 10 yearsI just tried that...didnt work. no errors just didnt load anything.
-
Satpal over 10 years@sirbombay, can you post your controller method and js script where you are consuming it