在iframe中使用Html.Raw()

时间:2014-03-06 20:17:26

标签: jquery css iframe razor

我正在实现一个linqpad工具来从序列化对象中获取html格式的结果,但是,当我在我的视图中转储原始HTML时,它包含了它自己的CSS。我想在iframe中封装它以保留所有其他CSS。

我遇到的问题是字符串DumpHTML

中的引号

上下文写入我的模型

var writer = LINQPad.Util.CreateXhtmlWriter(true);
writer.Write(objectToSerialize);
strHTML = writer.ToString();

只是将结果转储到页面上

$(function () {
        var ifrm = document.getElementById('myIframe');
        ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
        ifrm.document.open();
        ifrm.document.write('@Html.Raw(Model.DumpHTML)');
        ifrm.document.close();
    });

这就是我的输出:

$(function () {
        var ifrm = document.getElementById('myIframe');
        ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
        ifrm.document.open();
        ifrm.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta name="Generator" content="LINQ to XML, baby!" />
  <style type='text/css'>
body
{
    margin: 0.3em 0.3em 0.4em 0.5em;
    font-family: Verdana;
    font-size: 80%;
    ....

这有什么办法吗?最终问题是所有自动生成的样式都覆盖了页面上的css。

0 个答案:

没有答案