Reputation: 133
I render some page from the server using Razor(.cshtml) syntax. The page has some HTML data which I render as:
<div class="html-body">
@Html.Raw(HtmlText)
</div>
I have some external CSS loaded on this page, that quite frequently mess up my HTML content in html-body
class. So I want to use an Iframe instead of div. But that doesn't seem to work.
Is there a way to create Iframe directly from razor view? Or maybe some hack around to prevent any external loaded css files to exclude html-body
class?
Thanks
EDIT:
I tried the following:
<iframe>
@Html.Raw(HtmlText)
</iframe>
But it would just render as blank area.
Upvotes: 0
Views: 2185
Reputation: 686
You can use the srcdoc attribute, such as:
<iframe srcdoc="@Model.HTML"></iframe>
Upvotes: 2
Reputation: 1
all u have to do is: 1- create a partial view (.cshtml) 2- paste your all html source and css files to the file you named for example (IframeAction.cshtml) - don't forget to check true css, js patch. 3- put the below code into your HomeController
//in your HomeController
public PartialViewResult IframeAction()
{
return PartialView();
}
4- paste this below code in your destination page to call your html files(IframeAction.cshtml)
<iframe src="IframeAction/cshtml" frameborder="0" style="overflow:hidden; min-height:600px; height:100%; width:100%" height="100%" width="100%"></iframe>
5- the end. now after running the destination page, you can see the IframeAction.cshtml in that page, in a div you set.
Upvotes: 0