2014-02-26 205 views
1

我有一個簡單的Email Composer類,我從中獲取所有應用程序電子郵件內容。 在本例中,它將產品發送到電子郵件。將字符串渲染爲MVC視圖

現在,我想打印他們以及和我試圖重新用同樣的方法來抓住從電子郵件作曲家,並輸出到瀏覽完整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> 

如果我通過bodyModel我得到的分析器錯誤,所以我使用的ViewBag代替。

作爲輸出:在所有

  • @Html.Raw(email.Length)將輸出17463
  • @email將輸出代碼

    • @Html.Raw(email)將輸出什麼,但瀏覽器將其輸出,不分析它(下圖)

    我缺少什麼?我知道這一定是一個非常簡單的事情,但我完全空白......使用@email

    enter image description here

  • 回答

    0


    瀏覽器輸出試試這個

    @(new HtmlString(mystring)) 
    

    @MvcHtmlString.Create(ViewBag.Stuff) 
    
    +2

    你應該真的解釋爲什麼'@ Html.Raw'不起作用以及你的解決方案爲什麼起作用? –

    相關問題