2014-02-26 3 views
1

저는 간단한 전자 메일 작성기 클래스를 사용하여 모든 응용 프로그램 전자 메일 콘텐츠를 가져옵니다. 이 예에서는 제품을 전자 메일로 보냅니다.문자열을 MVC로 렌더링합니다.

지금, 나뿐만 아니라 인쇄을 원하는, 그리고 내가보기에 이메일 작곡가 출력을에서 전체 HTML을 잡기 위해 같은 방법을 다시 사용하려고 해요. 내가 파서에 오류가 발생할 수행 bodyModel A와 내가 전달하면

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

@Html.Raw(email) 

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

, 그래서 대신 ViewBag을 사용하고 있습니다 :

컨트롤러 액션

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

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

전망이다 .

출력으로서

모든

  • @Html.Raw(email.Length)가 출력 17463
  • @email 출력 할 것이다 코드

    • @Html.Raw(email)가 출력 아무것도하지만 브라우저를 출력하고, 그것이 (아래 그림)
    • 파싱하지

    내가 무엇이 누락 되었습니까? 이

    @(new HtmlString(mystring)) 
    

    을 시도 내가 정말 간단한 일해야합니다 알고,하지만 난


    브라우저 출력 @email

    enter image description here

  • 답변

    0

    를 사용 ... 완전히 비어있어 나

    @MvcHtmlString.Create(ViewBag.Stuff) 
    
    +2

    '@ Html.Raw '가 작동하지 않는 이유와 솔루션이 작동하는 이유를 설명해야합니다. –