1

我有一个简单的 Email Composer 类,我从中获取所有应用程序电子邮件内容。在此示例中,它将产品发送到电子邮件。

现在,我也想打印它们,并且尝试重新使用相同的方法从电子邮件编辑器中获取完整的 html 并将其输出到视图。

控制器动作

public ActionResult PrintRules()
{
    var products = rep.ListAllProductsByCompanyId(currentCompany.company_id);
    string body = mail.GetProductRules(products);

    ViewBag.email = HttpUtility.HtmlEncode(body);
    return View();
}

观点是:

@{
    Layout = null;
    string email = HttpUtility.HtmlDecode(ViewBag.email);
}

@Html.Raw(email)

<script>
     window.print();
</script>

如果我将bodya 作为 a传递,Model我会在解析器上遇到错误,所以我使用的是a ViewBag

作为输出:

  • @Html.Raw(email)什么都不输出
  • @Html.Raw(email.Length)将输出17463
  • @email将输出代码但浏览器输出它,不解析它(下图)

我错过了什么?我知道这一定是一件非常简单的事情,但我完全空白......


浏览器输出使用@email

在此处输入图像描述

4

1 回答 1

0

尝试这个

@(new HtmlString(mystring))

或者

@MvcHtmlString.Create(ViewBag.Stuff)
于 2014-02-26T12:52:49.770 回答