.Net Razor +将原始HTML传递给@helper宏

时间:2013-06-27 13:33:09

标签: .net razor

我想将原始html传递给@helper宏...这可能吗?例如:

@helper oneColumn(string content) {
<div class="row">               
  <div class="twelve columns">
    @content                    
  </div>
</div>
}

@put.oneColumn(
  <h1 id="page-heading">HELLO WORLD!</h1>
)

3 个答案:

答案 0 :(得分:26)

@helper oneColumn(Func<dynamic,HelperResult> content) {
<div class="row">               
  <div class="twelve columns">
    @content(null)                    
  </div>
</div>
}

@put.oneColumn( @<h1 id="page-heading">HELLO WORLD!</h1>)

答案 1 :(得分:1)

使用@Html.Raw HTML帮助器,或将内容设为IHtmlString

答案 2 :(得分:0)

@helper oneColumn(string content) {
var contentHtml = new HtmlString(content);
<div class="row">               
  <div class="twelve columns">
    @contentHtml                    
  </div>
</div>
}

@put.oneColumn(
  "<h1 id=\"page-heading\">HELLO WORLD!</h1>"
)